davedjohnson Posted July 27, 2005 Share Posted July 27, 2005 I have primitive GEO_Primiive *prim; that has 3 points. I have an extra point that is coplanar with the prim and I want to either: make a new primitive with all four points (in the right order) and delete the 3pointed one, or insert the extra point into the vertex list. Any ideas as to how to do it? Dave Quote Link to comment Share on other sites More sharing options...
George Posted July 27, 2005 Share Posted July 27, 2005 Generally, you'd have to cast your GEO_Primitive to something a little more descriptive. For example, you can't add a single vertex to a NURBS surface, but you can add a single vertex to a GEO_Face. In GEO_Face.h, have a look near the insertVertex() method, that should get you what you want. (I'm assuming that what you really have is a polygon, which can be cast to a GEO_Face. To know for sure, you can use the getPrimitiveId() method). Hope that helps. George. Quote Link to comment Share on other sites More sharing options...
davedjohnson Posted July 27, 2005 Author Share Posted July 27, 2005 Yes, I do have a polygon, sorry I didn't mention that. I rebuilt my GEO_primitive to a GEO_PrimPoly, and tried the insertVertex() method, but I don't think it did what I wanted. It did insert the vertex to my poly, but it didn't connect the edges. My getVertexCount() went from 3 to 4, but the point was not connected. Also, I just found the GEO_Face::pointInFace() method and I can't figure out how to use it. I can get it to compile, but it crashes Houdini everytime. Here's what I put in: GU_PrimPoly *addPlanar; GEO_Primitive *prim; GEO_Point *farPt; int isInside; farPt = gdp->points().tail(); // this isn't exactly what I have, it really picks one that isn't in prim // but is planar with prim. prim = gdp->primitives().head(); if(addPlanar = GU_PrimPoly::build(gdp, prim->getVertexCount(), GU_POLY_CLOSED, 0) { for(int i = 0;i < prim->getVertexCount(); i++) { (*addPlanar)(i) = prim->getVertex(i); } } isInside = addPlanar->pointInFace( (const UT_Vector3 &)farPt.getPos(), (const UT_Vector3 *)&addPlanar->computeNormal()); I'm clearly not getting the line with pointInFace right, though I can get it to compile. How is this REALLY used? Dave Quote Link to comment Share on other sites More sharing options...
George Posted July 27, 2005 Share Posted July 27, 2005 I rebuilt my GEO_primitive to a GEO_PrimPoly, and tried the insertVertex() method, but I don't think it did what I wanted. It did insert the vertex to my poly, but it didn't connect the edges. My getVertexCount() went from 3 to 4, but the point was not connected. In insertVertex() you give it a point that you want to assign to the new vertex and optionally an index of where to insert it. By default it inserts it at the beginning. It's strange that doesn't work for you. Could it be that you give it a point that is already on your polygon and you are getting overlapping vertices? I'm clearly not getting the line with pointInFace right, though I can get it to compile. Hmm... do you know where exactly is it crashing? It looks like the farPt call to getPos() should at least be farPt->getPos()... I'm not sure how it compiles otherwise. George. Quote Link to comment Share on other sites More sharing options...
davedjohnson Posted July 27, 2005 Author Share Posted July 27, 2005 Hmm... do you know where exactly is it crashing? It looks like the farPt call to getPos() should at least be farPt->getPos()... I'm not sure how it compiles otherwise.George. 19937[/snapback] farPt was already in my poly and I was getting overlapping edges. And the farPt call to getPos() was a typo in my post. I was doing farPt->getPos(). Other than that, does it look like this is how one would use pointInFace()? Dave Quote Link to comment Share on other sites More sharing options...
George Posted July 28, 2005 Share Posted July 28, 2005 Other than that, does it look like this is how one would use pointInFace()? 19939[/snapback] Does your compiler complain about taking the address of a temporary? computeNormal() returns a full-on UT_Vector3 -- it is computed and returned everytime, and usually taking the address of a temporary variable is not a good idea. Try this instead: UT_Vector3 nml = addPlanar->computeNormal(); isInside = addPlanar->pointInFace( (const UT_Vector3 &)farPt.getPos(), &nml); The problem may have to do with when the temporary is deleted. If the expression is fully evaluated and the compiler deletes the temporary before it runs the pointInFace() function, you now have a pointer to deleted memory and you may get a crash. (Having said that, I do believe that the standard requires that temporaries be deleted after the entire line is run -- but why take chances with things as pliable as standards? ) If this turns out to be the problem, it would be interesting to know what compiler you're running. Hope that helps George. Quote Link to comment Share on other sites More sharing options...
davedjohnson Posted July 28, 2005 Author Share Posted July 28, 2005 Does your compiler complain about taking the address of a temporary? computeNormal() returns a full-on UT_Vector3 -- it is computed and returned everytime, and usually taking the address of a temporary variable is not a good idea. Try this instead: 19962[/snapback] Yes, it was complaining about taking the address of a temporary. I'll try your suggestion. Thanks again. Dave 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.