Jump to content

create point attribute outside cookmysop().


Syrux

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.

Link to comment
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.

Link to comment
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.

Link to comment
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
Link to comment
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.

Link to comment
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
Link to comment
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
Link to comment
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
Link to comment
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
Link to comment
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
Link to comment
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
Link to comment
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
Link to comment
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

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...