Jump to content

Resample Geo In Gdp?


Recommended Posts

Hello,

OK, so I am attempting a little HDK thing but at my current pace I can get about 2 lines of code per day written :( My C++ being super-rusty and many years old doesn't help. Basically, I want to add a line (likely many lines eventually) and then resample those lines. Why not just add the lines with the points you already want, you ask. Aye, I ask myself the same question. Regardless, this is the way I'm trying to understand since it parallels SOPs nicely.

	gdp = new GU_Detail();
	gdp->clearAndDestroy();

	GU_PrimPoly *mypoly =
		GU_PrimPoly::build(gdp, 2, 1 /* open */);

	UT_Vector3 pos1;
	UT_Vector3 pos2;

	pos1 = (-1,-1,-1);
	pos2 = (1,1,1);

	(*mypoly)(0).getPt()->getPos() = pos1;
	(*mypoly)(1).getPt()->getPos() = pos2;

	GU_Resample myresampler;
	myresampler.setType(GU_Resample::ARC);
	myresampler.setMethod(GU_Resample::DIST);
	myresampler.setMaxSegments(50);

	int len = myresampler.totalLength(mypoly);
	myresampler.setLength((float)len/50.0f);

	GU_PrimPoly *newpoly = (GU_PrimPoly*)myresampler.resampleFace(mypoly);

	 gdp->save("line.bgeo",0,options);

The above compiles and "works" in the sense that I end up with 2 polygons with 57 points in the line.bgeo file.

However, there are numerous things I don't get. First off, how did the new refined polygon get into the gdp? Second, how do I get _only_ the new refined polygon in the gdp? I want to replace the original 2 point poly with the new refined one. Do I make a new gdp and destroy the old on? Clear the old one? If so, how to get the newpoly into the gdp?

All assistance greatly received!

Cheers,

Peter B

Link to comment
Share on other sites

I never done this myself but you could look at a couple of methods.

You could build your original line in a seperate GU_Detail() that would keep it out of the final gdp.

Then resample your poly and use GB_Detail::appendPrimElem to insert it in the gdp

maybe?

Link to comment
Share on other sites

Hey Peter, this will be a bit off the top of my head.. so take it with a grain of salt.

how did the new refined polygon get into the gdp?

This single line builds the poly in the gdp you pass it, nothing more should be needed to create a new poly:

GU_PrimPoly *mypoly = GU_PrimPoly::build(gdp, 2, 1 /* open */);

how do I get _only_ the new refined polygon in the gdp?

Hmm.. good question. I've never used GU_Resample before, certainly looks like you need to generate another poly rather then resample it in place.. maybe you can say:

mypoly = (GU_PrimPoly*)myresampler.resampleFace(mypoly);

It may crash, but worth a try. Depending on what you want to do, there are other methods to resample that will do it in place, but I don't think they have the flexibility of the class you're using - GU_Detail has a subdivide, refine, polyspline, divideEdges. One of those may do what you want as well.

With what you have I'd just delete the old one:

gdp->deletePrimitive(mypoly,1);

Daniel

Link to comment
Share on other sites

Hi guys,

Thanks for the tips! I hope to get back to this project soon :) I got into the HDK once before (mostly writing commands and expressions) and now that I'm in there again I don't want to lose touch, 'cause it's a long, long hill to climb back up if you slip off :)

Cheers,

Peter B

Link to comment
Share on other sites

Hi Simon,

Hmmmmm. I've got the line and resample working, but this is stumping me as it does look like what I need for something further into the code.

Being a C++ moron, I don't understand how this would work. Let's say I have:

GU_Detail *tempgdp;

GU_Detail *finalgdp;

tempgdp = new GU_Detail();

finalgdp = new GU_Detail();

tempgdp->clearAndDestroy();

finalgdp->clearAndDestroy();

GU_PrimPoly *mypoly =

GU_PrimPoly::build(gdp, 2, 1 /* open */);

//

// other stuff done to the *mypoly like positioning points and resampling

//

//So now I want to append it to the finalgdp... I'm not clear how!!

The function returns a GB_Primitive* ... how does that help me?

GB_Primitive *appendPrimElem(GB_Primitive *prim,

int cleargroups = 1)

Cheers,

Peter B

I never done this myself but you could look at a couple of methods.

You could build your original line in a seperate GU_Detail() that would keep it out of the final gdp.

Then resample your poly and use GB_Detail::appendPrimElem to insert it in the gdp

maybe?

Link to comment
Share on other sites

The function returns a GB_Primitive* ... how does that help me?

GB_Primitive *appendPrimElem(GB_Primitive *prim,

int cleargroups = 1)

Cheers,

Peter B

Being a bit of a C++ moron myself I can't say if this will work without trying it. Its not a method I've ever used but i did wonder if you could do something like this

GB_Primitive *finalprim = finalgdp->appendPrimElem((GB_Primitive *)mypoly);

It depends if you can cast a GU_PrimPoly as a GB_Primitive.... it looked (given a very brief glance) like it might be possible.

If not I can't believe there isn't a similar function somewhere for GU_PrimPoly's

have you tried asking Sesi support? I bet they could clear this up, I'd be very interested for future reference what the "correct" way to do this actually is.

Link to comment
Share on other sites

Hi Simon,

Not understanding the code doesn't help, however I did get this to work at the end of each loop:

finalgdp->merge(*gdp);

delete gdp;

I am not sure that this is the most effecient way of doing it since I am creating then destroying the temp gdb each time... however it works, and that's good enough for me!

Cheers,

Peter B

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