hoknamahn Posted June 18, 2005 Share Posted June 18, 2005 Hi guys! I try to do simple things and I have some questions. For example, I want to create one point (with x, y, z coords) for each poly from incoming geometry. Question 1: Whether correctly I add points in existing geometry? Can be there is more correct way? GEO_Point *ppt = new GEO_Point(pos, adata); temp_gdp->insertPoint(ppt); gdp->merge(*temp_gdp); Question 2: In the example above to GEO_Point () constructor it is transferred desirable coordinates pos, but the created points are not placed in the coordinates transferred to the constructor. Why? Whether it is required to transfer necessarily coordinates after creation of objects? Quote Link to comment Share on other sites More sharing options...
George Posted June 18, 2005 Share Posted June 18, 2005 Hello, I think it would probably be better if you simply called GEO_Point *ppt = gdp->appendPoint(pos, adata); Unless there is some reason you need a temporary gdp. Also, there is an argument to appendPoint() (and insertPoint()) to tell it whether or not the attribute data you are sending in should be managed by the point or whether it should make a new copy for itself (using the values you provide). Take care, George. Quote Link to comment Share on other sites More sharing options...
hoknamahn Posted June 18, 2005 Author Share Posted June 18, 2005 Hello,I think it would probably be better if you simply called GEO_Point *ppt = gdp->appendPoint(pos, adata); Unless there is some reason you need a temporary gdp. Also, there is an argument to appendPoint() (and insertPoint()) to tell it whether or not the attribute data you are sending in should be managed by the point or whether it should make a new copy for itself (using the values you provide). Take care, George. 18901[/snapback] Thanks, George! appendPoint() works fine My argument to use a temporary gdp is the toggle of my custom SOP - Keep Original Geometry. Quote Link to comment Share on other sites More sharing options...
edward Posted June 19, 2005 Share Posted June 19, 2005 To copy geometry from an input, SOP_Node::duplicateSource() is much easier. Quote Link to comment Share on other sites More sharing options...
hoknamahn Posted June 20, 2005 Author Share Posted June 20, 2005 Thanks for hint, edward Another one dumb question: which method from GB_AttributeData I can use to assign the attribute of any type? Quote Link to comment Share on other sites More sharing options...
AndrewVK Posted June 20, 2005 Share Posted June 20, 2005 Look at GEO_Detail.h addPointAttrib addVertexAttrib addPrimAttrib e.t.c example: int primAttr1 = gdp->addPrimAttrib("angle", sizeof(float), GB_ATTRIB_FLOAT, &angle); gdp->addVariableName("angle", "ANGLE"); Quote Link to comment Share on other sites More sharing options...
hoknamahn Posted June 20, 2005 Author Share Posted June 20, 2005 Look at GEO_Detail.haddPointAttrib addVertexAttrib addPrimAttrib e.t.c example: int primAttr1 = gdp->addPrimAttrib("angle", Quote Link to comment Share on other sites More sharing options...
hoknamahn Posted June 23, 2005 Author Share Posted June 23, 2005 Okay. I shall try to paraphrase a question: whether it is possible to add attributes in process of addition of geometry? Let me explain. For example, I have an empty scratch_gdb in which I add points in process of search of geometry from gdb. In process of addition of points I would like to add some attributes. Whether it is possible to make it in one pass? scratch_gdp = new GU_Detail(); FOR_ALL_PRIMITIVES(gdp,prim) { area = prim->calcArea(); pos = prim->baryCenter(); ppt = scratch_gdp->appendPoint(pos, adata); // I want to add the point attributes here } // And I don't want to add attributes in this place Is it possible? For what the parameter adata in a appendPoint () method is intended? Quote Link to comment Share on other sites More sharing options...
George Posted June 25, 2005 Share Posted June 25, 2005 Is it possible? For what the parameter adata in a appendPoint () method is intended? The adata parameter is used when, for example, you'd like to make a copy of a point, and you'd like to use the original point's attributes for the new point you are making. So without an original point to copy attributes from, it is tricky to use the GB_AttributeData class directly. What kind of attribute data would you like to add. You can set up the attributes before starting the loop. Keep track of the indices of where your attributes have been added like so: int temperature_index = gdp->addPointAttrib("temperature", sizeof(float), GB_ATTRIB_FLOAT, &default); Then in your loop, you can access this attribute for new point (in the normal way) and modify it as desired. Hope that helps. George. Quote Link to comment Share on other sites More sharing options...
hoknamahn Posted June 27, 2005 Author Share Posted June 27, 2005 You can set up the attributes before starting the loop Hey, George... I think it is impossible, because my scratch_gdp is empty before starting the loop. If I understand it right, I can create the attribute only for geometry which already exists. So I can write something like this scratch_gdp = new GU_Detail();// It's doesn't have any sense hereint area_index = scratch_gdp->addPointAttrib("parea", Quote Link to comment Share on other sites More sharing options...
Guest xionmark Posted June 27, 2005 Share Posted June 27, 2005 scratch_gdp = new GU_Detail(); // It's doesn't have any sense here int area_index = scratch_gdp->addPointAttrib("parea", sizeof(float), GB_ATTRIB_FLOAT, &area); float *pa; FOR_ALL_PRIMITIVES(gdp,prim) { ... ppt = scratch_gdp->appendPoint(pos, adata); // And it's doesn't have any sense here too because current point doesn't have the custom attributes pa = (float *)ppt->getAttribData(area_index); // Same problem here *pa = area; } This looks correct, have you used a debugger to find where Houdini crashes? Have you looked at the crash log? --Mark Quote Link to comment Share on other sites More sharing options...
hoknamahn Posted June 27, 2005 Author Share Posted June 27, 2005 This looks correct, have you used a debugger to find where Houdini crashes? Have you looked at the crash log?--Mark 19086[/snapback] No, I didn't do it. It seemed to me, that there is no sense to add attribute in *empty gdb*. I am not assured that the addPointAttribute() function particularly does, but it seems to me, that it adds attribute to *already existing* points in gdb (it allocates memory for given attribute of the necessary type and creates the pointer on them and also returns an index of the created attribute. Something like this?). If it actually so I'll change algorithm. Quote Link to comment Share on other sites More sharing options...
Guest xionmark Posted June 27, 2005 Share Posted June 27, 2005 I don't see why that wouldn't work, I'm assuming I suppose that the constructor intializes all the needed data structures to start adding points, prims, attr's, etc. Just curious what would happen if you did a clearAndDestroy() on the scratch_gdp. Quote Link to comment Share on other sites More sharing options...
edward Posted June 27, 2005 Share Posted June 27, 2005 Adding a point attribute on an empty gdp would just define the attribute its attribute dictionary so that when you do add a point, it creates a point with the default attribute values. Use appendPoint() in your loop without specifying adata. Once you have a new point, you can set the attribute values via getData(). Quote Link to comment Share on other sites More sharing options...
George Posted June 28, 2005 Share Posted June 28, 2005 It may help to realize that in Houdini, all points must have the same number/size of attributes defined. You can't have an attribute on one point, but not the other. So adding an attribute to a gdp, simply means adding it to the description of what a set of point attributes looks like. All points share that description. But, as Edward says, each point has its own data for each attribute, which you can access using getData(). George. Quote Link to comment Share on other sites More sharing options...
Guest xionmark Posted June 28, 2005 Share Posted June 28, 2005 It may help to realize that in Houdini, all points must have the same number/size of attributes defined. You can't have an attribute on one point, but not the other. 19097[/snapback] Oh! Is that what he's trying to do? Yea, you can't do that ... Quote Link to comment Share on other sites More sharing options...
hoknamahn Posted June 28, 2005 Author Share Posted June 28, 2005 Oh! Quote Link to comment Share on other sites More sharing options...
hoknamahn Posted July 1, 2005 Author Share Posted July 1, 2005 I hope has not strongly bothered with the silly questions? So... The problem with crash of Houdini is solved, but the reason for me while is unknown. I would like to learn, why if I use appendPoint (pos, adata) there is a crash, and if use appendPoint () the flight is normal? Whether there are any specific features? And why in the HDK examples I see ppt = gdp->appendPoint(); ppt->getPos().assign((float)x/(float)xres, (float)y/(float)yres, 0, 1); instead of laconic pos.assign((float)x/(float)xres, (float)y/(float)yres, 0, 1); gdp->appendPoint(pos, adata); Quote Link to comment Share on other sites More sharing options...
George Posted July 2, 2005 Share Posted July 2, 2005 ...And why in the HDK examples I see ppt = gdp->appendPoint(); ppt->getPos().assign((float)x/(float)xres, (float)y/(float)yres, 0, 1); instead of laconic pos.assign((float)x/(float)xres, (float)y/(float)yres, 0, 1); gdp->appendPoint(pos, adata); 19186[/snapback] I suppose that depends entirely on where you are getting your 'adata' from. If it is invalid attribute data, or of the wrong size, the results, as you have seen, are quite unpredictable. George. Quote Link to comment Share on other sites More sharing options...
hoknamahn Posted July 2, 2005 Author Share Posted July 2, 2005 I suppose that depends entirely on where you are getting your 'adata' from. If it is invalid attribute data, or of the wrong size, the results, as you have seen, are quite unpredictable. 19195[/snapback] Bingo! Here it the reason of crash! Now I can sleep easy Thanks! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.