Jump to content
Syrux

create point attribute outside cookmysop().

Recommended Posts

I realize that there is some inheritance/hierarchy witchcraft that is stopping my code from compiling properly (undeclared identifier). I have tried many snippets of code that are supposed to create attributes, but they only work inside the cookmysop function. So, how can I create an attribute outside cookmysop() that is at the same time accessible by the cookmysop function and avoids inheritance problems?

 

Thanks in advance.

Share this post


Link to post
Share on other sites

It's not true. You can add attributes anywhere, all you need is a pointer to your geometry. Basically you get your geometry in cookMySop by calling duplicateSource(), then you can pass gdp pointer anywhere you want.

I'm not sure, but i think you can also do something with a geometry in a constructor of your SOP_Node.

Share this post


Link to post
Share on other sites

Edward in the sidefx forum replied that it is not allowed. I really don't want to create an attribute everytime the sop cooks. I am working right now with the CPP_Wave example. If you know how to create the attribute, please tell me.

Share this post


Link to post
Share on other sites

It's not true. You can add attributes anywhere, all you need is a pointer to your geometry. Basically you get your geometry in cookMySop by calling duplicateSource(), then you can pass gdp pointer anywhere you want.

I'm not sure, but i think you can also do something with a geometry in a constructor of your SOP_Node.

Edward in the sidefx forum replied that it is not allowed. I really don't want to create an attribute everytime the sop cooks. I am working right now with the CPP_Wave example. If you know how to create the attribute, please tell me.

Share this post


Link to post
Share on other sites

You are writing SOP? If not, of course it's not allowed to modify geometry outside your operator, although you can do it, it's just a very bad idea. So, if you are writing sop, whats a problem to add attributes in cookMySop?

Share this post


Link to post
Share on other sites

You are writing SOP? If not, of course it's not allowed to modify geometry outside your operator, although you can do it, it's just a very bad idea. So, if you are writing sop, whats a problem to add attributes in cookMySop?

Yes, I am writing a SOP. The problem is that I need to create a initial value/attribute. Imagine you have a grid then each point checks its neighbours (like the game of life), if that neighbour is blue then the point that its checking neighbours also becomes blue, and so on. So, If I create the attribute each time the sop cooks, the points will never change, because they will always have the initial value. I have tried the folllowing snipet that doesn't work. but I am really out of ideas:

 

void createAttr(GU_Detail *gdp){
    GA_RWAttributeRef attr;                                 // This two lines
    attr = gdp->addFloatTuple(GA_ATTRIB_POINT, "Normal",3); // work perfectly inside the cookmysop()
}

I found this SOP code that creates a geometry pointer and adds atributters outside the cookmysop, I tried to do the same but I get the same errors. 

bool SOP_Centroid::createBaseGdp()
{

m_baseGdp = new GU_Detail;
m_baseGdpHdl.allocateAndSet(m_baseGdp,true);
bool ret_val = true;
if (m_addBBoxDimension)
{

//UT_Vector3 *sizeDef = new UT_Vector3(1,1,1);
GU_DetailHandleAutoWriteLock wLock(m_baseGdpHdl);
m_dimID = wLock.getGdp()->addFloatTuple(GA_ATTRIB_POINT,GA_SCOPE_PUBLIC,sizeAttrName.buffer(),3,GA_Defaults(1.0f));
.............
Edited by Syrux

Share this post


Link to post
Share on other sites
Guest mantragora

I found this SOP code that creates a geometry pointer and adds atributters outside the cookmysop...

No it doesn't. This method is executed inside cookMySop() in line 1018. To create something SOP have to cook.

Share this post


Link to post
Share on other sites

No it doesn't. This method is executed inside cookMySop() in line 1018. To create something SOP have to cook.

Well, that was my last resource. Any ideas? What if I create two cookmysop: one time dependant and the other time independent?

Edited by Syrux

Share this post


Link to post
Share on other sites
Guest mantragora

Why do you have to create attribute and compare it in the same SOP? That assumes that you expect that geometry on your input comes with something that you want to compare. So why not add second input that will be used as a comparision value, and then in you SOP use it to walk thru your geometry and set values?

And if you insists, you can compare you newly created attribute with you input geometry, which is const, and apply modification only to duplicated geometry.

This gets const geometry from first input

auto gdp0 = inputGeo(0, context);
This creates gdp in current SOP.

duplicateSource();
Ude gdp0 as a lookup, and set values in gdp. Edited by mantragora

Share this post


Link to post
Share on other sites

@Mantra

 

Why do you have to create attribute and compare it in the same SOP? That assumes that you expect that geometry on your input comes with something that you want to compare. So why not add second input that will be used as a comparision value, and then in you SOP use it to walk thru your geometry and set values?

 

Interesting solution. But unfortunately, I don't need to compare attributes, I just need to create the attribute. Like in the Game of Life. You don't compare initial values, you call the current value of neighbors.

 

But as I explained before, I can't create the attribute if I need that attribute to change over time, that's why I need to create the attribute only one time (outside cookmysop).

Edited by Syrux

Share this post


Link to post
Share on other sites
Guest mantragora

That means you need something time dependent. Maybe it's time to look into POPs/DOPs?

Share this post


Link to post
Share on other sites

@Mantra

 

Temporal solution:

 

fpreal frame = OPgetDirector()->getChannelManager()->getSample(context.getTime());

if (frame == 1){
create attribute;
}

Share this post


Link to post
Share on other sites
Guest mantragora

You could also check if the attribute already exists, if so, just get it, otherwise create it.

I'm not sure which attribute creation method you will take, but it should look something along those lines:

auto normalRef = gdp->findFloatTuple(GA_ATTRIB_POINT, "N", 3);
if (normalRef.isInvalid()) normalRef = gdp->addFloatTuple(GA_ATTRIB_POINT, "N", 3);
	
auto normalTuple = normalRef.getAIFTuple();
Edited by mantragora
  • Like 1

Share this post


Link to post
Share on other sites

Ok, That's basically my code, Another thing I want to get the bounding box, do I have to do it the same way?

 

UT_BoundingBox bbox;
gdp->getPointBBox(&bbox, 0);
cout << bbox.ymax();

This works, but inside (again) cookmysop(). I know that there are some classes that allows you to define it outside the cook, like the VRAY procedural. But unfortunately, I'm working with point clouds.

 
Edited by Syrux

Share this post


Link to post
Share on other sites
Guest mantragora

Why are you so afraid of cookMySop()? This is you Main() method. It's like you would like to create program, but to run it you would like to use everything but Main() :D

No other class will solve your problem. VRAY is for rendertime procedural generation. It has nothing to do with SOPs, beside that it takes the data they create.

  • Like 1

Share this post


Link to post
Share on other sites

@Mantra

 

Funny thing is that I just started with HDK few days ago (when I made the first question), I now I am talking with you about these things, thank you for sharing your knowledge with me.

 

Have a good night/day!

Edited by Syrux

Share this post


Link to post
Share on other sites

That means you need something time dependent. Maybe it's time to look into POPs/DOPs?

Does this means that I cant make a simple Game of Life or a Flood Fill algoritm in HDK,  using SOP?

Edited by Syrux

Share this post


Link to post
Share on other sites
Guest mantragora

I'm not familiar with any of those two algorithms, so I'm not sure what to look for to solve this problem. If the code works for you, that's cool. Just make sure that you don't write code using deprecated stuff.

 

 

Does this means that I cant make a simple Game of Life or a Flood Fill algoritm in HDK,  using SOP?

 

 

@Mantra, found it! Oh my gosh what a headache, look at the code in this question: http://forums.odforce.net/topic/4310-hdk-sop-sim-cook-problem/?hl=timedep

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×