Edge Index
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 13/03/2011 at 11:43, xxxxxxxx wrote:
User Information:
Cinema 4D Version:
Platform:
Language(s) :---------
Hi there,I know that points and polygons have an index, but what about edges ?
For example when I want to select the Edges of a polygon within a plugin, how do i get the indieces of theese Edges ?Thanks, nux
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 14/03/2011 at 22:58, xxxxxxxx wrote:
*push*
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 14/03/2011 at 23:26, xxxxxxxx wrote:
Here you go:
void DumpSelectedEdges(PolygonObject *op) { BaseSelect *pEdgeSel = op->GetEdgeS(); if( pEdgeSel->GetCount() == 0) return; LONG polyNdx, edgeNdx, edge, seg = 0, smin, smax; while( pEdgeSel->GetRange(seg++,&smin;,&smax;) ) { for( edge=smin; edge<=smax; edge++ ) { edgeNdx = edge % 4; polyNdx = (edge - edgeNdx) / 4; switch(edgeNdx) { case 0: GePrint("poly: "+LongToString(polyNdx)+" edge: 0 (poly.a -> poly.b)"); break; case 1: GePrint("poly: "+LongToString(polyNdx)+" edge: 1 (poly.b -> poly.c)"); break; case 2: GePrint("poly: "+LongToString(polyNdx)+" edge: 2 (poly.c -> poly.d)"); break; case 3: GePrint("poly: "+LongToString(polyNdx)+" edge: 3 (poly.d -> poly.a)"); break; } } } }
...also take a look at GetSelectedEdges() and SetSelectedEdges() in the SDK docs.
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 15/03/2011 at 08:13, xxxxxxxx wrote:
Hm, but does it give me the index of an edge ? I mean the index of a edge not seen form a polygon but a hole object.
Let's say I have a mesh and want to select an egde by script, a specific one.
sel->Select(my_edge_index);
But how do i get this edge index ? I can't view the edge indieces in the Structure Manager for example ..
Thanks anyway,
-nux -
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 15/03/2011 at 08:37, xxxxxxxx wrote:
Take a look at the SetSelectedEdges() routine in the SDK docs. The 'unique' edge ID/index is done through the Neighbor object.
EDIT: actually, the SDK docs don't seem all that clear (for answering your question)... it seems like I've done something similar to what you are looking for, but I can't find the code off-hand and can't change gears to look for it atm, but if I come up with anything, I'll let you know.
EDIT2: actually, you should be able to figure it out with those docs (along with GetSelectedEdges())... you just need to know which edge _and_ what polygon that edge belongs to. You then set up a BaseSelect with the edge(s) selected by: (polyNdx * 4) + edgeNdx for each edge you want selected.
...once you have that, you call GetSelectedEdges() to convert your BaseSelect to something SetSelectedEdges() can use and... et-voila.
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 18/03/2011 at 03:39, xxxxxxxx wrote:
You can get a unique edge index for selected edges through GetEdgeS() , GetSelectedEdges() and the Neighbor class.
Example, prints the indices of selected edges.
BaseObject *op = doc->GetActiveObject(); if (!op) return FALSE; if (op->GetType() == Opolygon) { Neighbor n; if (!n.Init(ToPoly(op)->GetPointCount(),ToPoly(op)->GetPolygonR(),ToPoly(op)->GetPolygonCount(),NULL)) return FALSE; BaseSelect *esel = ToPoly(op)->GetSelectedEdges(&n,ToPoly(op)->GetEdgeS()); LONG seg=0,a,b,i; while (esel->GetRange(seg++,&a,&b)) { for (i=a; i<=b; ++i) { // ... do something - i is the selected element GePrint(LongToString(i)); } } BaseSelect::Free(esel); }
cheers,
Matthias -
On 11/07/2014 at 21:20, xxxxxxxx wrote:
^Is this code by Matthias broken now?
I'm pretty sure it worked for me properly in R12. But now that I'm using it in R13 it's not working correctly. I'm getting a jibberish point ID from it.
Maxon changed the GetRange() function in R13. They added another required parameter to it. And I'm wondering if that's why this code no loger works correctly?This is how I'm using it in R13:
BaseObject *op = doc->GetActiveObject(); if (!op) return FALSE; if (op->GetType() == Opolygon) { Neighbor n; if (!n.Init(ToPoly(op)->GetPointCount(),ToPoly(op)->GetPolygonR(),ToPoly(op)->GetPolygonCount(),NULL)) return FALSE; BaseSelect *esel = ToPoly(op)->GetSelectedEdges(&n,ToPoly(op)->GetEdgeS()); LONG seg=0,a,b,i; while (esel->GetRange(seg++, MAXLONGl, &a, &b)) { for (i=a; i<=b; ++i) { // GePrint(LongToString(i)); } } BaseSelect::Free(esel); }
MAXLONGl was added in R13. Is this causing my code to fail?
I'm writing an R13 plugin where I need to get the points in selected edges. And this is the only way I knew how to do it. But now it's not working anymore!-ScottA
-
On 12/07/2014 at 20:21, xxxxxxxx wrote:
Using a sphere as the test object. I'm finding the following results.
-There are 265 points in a sphere object
-Using the code Matthias posted. I get a total edge count of 552 edges
BaseSelect *esel = ToPoly(op)->GetSelectedEdges(&n,ToPoly(op)->GetEdgeS()); LONG count = esel->GetCount(); GePrint(LongToString(count)); //prints 552
-If I select a specific edge (100) with code and then I Ctrl + select points mode
The two points in edge 100 are: 27&51PolygonObject *obj = (PolygonObject* ) doc->GetActiveObject(); if(!obj || obj->GetType() != Opolygon) return FALSE; BaseSelect *selEdges = obj->GetEdgeS(); selEdges->Select(100); //In points mode the points of this edge are: 27&51
The coded posted in this thread seems to be returning "edge" index numbers. Which seems to be different from "point" index #s.
So how do I go about getting the point index numbers 27 & 51 from edge 100 with code?
Is there some math formula I need to use to convert edge index numbers to point index numbers?-ScottA
-
On 12/07/2014 at 21:10, xxxxxxxx wrote:
Hi Scott,
I didn't/don't really have the time to look closely at your issue/question, but a casual reading of it reminded me of a really old post of mine that may or may not be of some help, so I thought I'd link it - https://developers.maxon.net/forum/topic/3818/3267_ngon-info
Cheers.
-
On 12/07/2014 at 22:05, xxxxxxxx wrote:
Thanks Giblet.
Unless I'm not seeing it. I don't see anything in there that gets the point index numbers for a selected edge. :frowning2:-ScottA
-
On 13/07/2014 at 14:57, xxxxxxxx wrote:
OK. I got it.
In order to get the two points of a selected edge. You have to go farther than just the coded that Matthias posted. That only gets you half way there.This is my code for selecting the points in the selected edge/edges:
//This code selects the points in the selected egdes PolygonObject *obj = (PolygonObject* ) doc->GetActiveObject(); if(!(obj && (obj->GetType() == Opolygon))) return FALSE; BaseSelect *EdgeS = obj->GetEdgeS(); if(EdgeS->GetCount() < 1) return FALSE; //The number of edges = the number of polygons * 4 LONG maxEdgeCnt = obj->GetPolygonCount()*4; CPolygon *polygons = obj->GetPolygonW(); BaseSelect *PointS = BaseSelect::Alloc(); GeDynamicArray<LONG>EdgeInd; for(LONG i=0; i<maxEdgeCnt; i++) { if( EdgeS->IsSelected(i) ) { //GePrint(LongToString(i)); EdgeInd.Push(i); } } for(LONG i=0; i<EdgeInd.GetCount(); i++) //For each element in the EdgeInd array { LONG edge = EdgeInd[i]; LONG PolyInd = int(edge/4); LONG PolyEdgeInd = edge-4*(PolyInd); CPolygon Polygon = polygons[PolyInd]; //Store the selected points in memory in the "PointS" BaseSelect array if( PolyEdgeInd == 0) { PointS->Select(Polygon.a); PointS->Select(Polygon.b); } else if( PolyEdgeInd == 1) { PointS->Select(Polygon.b); PointS->Select(Polygon.c); } else if( PolyEdgeInd == 2) { PointS->Select(Polygon.c); PointS->Select(Polygon.d); } else if( PolyEdgeInd == 3) { PointS->Select(Polygon.d); PointS->Select(Polygon.a); } } //Select the points using the PointS array PointS->CopyTo(obj->GetPointS()); //Free the memory used BaseSelect::Free(PointS); EdgeInd.FreeArray();
Theoretically, I should also be able to use the GetRange() function to get the selected edges. Instead of using the IsSelected() function.
But for some strange reason. That function returns the wrong edge index#s every time I use it. And I don't know why.
So I had to figure out a different way to get the selected edges.-ScottA