Jump to content

Hdk Basics


Recommended Posts

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?

Link to comment
Share on other sites

  • Replies 84
  • Created
  • Last Reply

Top Posters In This Topic

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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");

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 here

int area_index = scratch_gdp->addPointAttrib("parea",

Link to comment
Share on other sites

Guest xionmark
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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

Guest xionmark

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.

Link to comment
Share on other sites

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().

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

Guest xionmark
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 ...

Link to comment
Share on other sites

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);

Link to comment
Share on other sites

...

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.

Link to comment
Share on other sites

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 :lol:

Thanks!

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...