# edge selection -> points [SOLVED]

• On 11/10/2014 at 10:17, xxxxxxxx wrote:

sure. i want to create some polygons which align to the edges given by the edge selection. something like the matrix extrude but based on the edges. so in the end i need the coordinates of the points belonging to the selected edges

• On 11/10/2014 at 10:22, xxxxxxxx wrote:

Then I'd recommend to go with the example. If you fail with that, please give me a short code example, which demonstrates, in which way it's not doing what you want.

Oh and by the way, I think, you should get the point indeces from the original BaseSelect.

• On 11/10/2014 at 10:25, xxxxxxxx wrote:

Originally posted by xxxxxxxx

Oh and by the way, I think, you should get the point indeces from the original BaseSelect.

really?? how? as i don't see a member which would give me those.

• On 11/10/2014 at 10:28, xxxxxxxx wrote:

It may be a bit cumbersome and there may be better ways to do so, but you can query indeces via IsSelected().

• On 11/10/2014 at 10:29, xxxxxxxx wrote:

i'll try things out now... thank you so far

• On 11/10/2014 at 10:31, xxxxxxxx wrote:

You are welcome.

• On 11/10/2014 at 11:45, xxxxxxxx wrote:

Got it working using the following code:

``````	selection = linkedSelection->GetBaseSelect();

LONG pcnt = ToPoly(source)->GetPointCount();
LONG fcnt = ToPoly(source)->GetPolygonCount();
LONG p1;
LONG p2;

Neighbor neighbor;
if (!neighbor.Init(pcnt, fadr, fcnt, nullptr)) return NULL;

LONG edgeCount = neighbor.GetEdgeCount();
for (int i=0; i<edgeCount;i++)
{
String nfo = "";
if (selection->IsSelected(i)) nfo = "Selected";
GePrint(LongToString(i)+": "+LongToString(p1)+"->"+LongToString(p2)+" "+nfo);
}
``````

Thanks again to everybode helping here :)

• On 11/10/2014 at 12:44, xxxxxxxx wrote:

hm, probably a bit to early with my joy...

for example if i have a cube as a basemesh and use the edge selection shown in the image. the console gives me the proper counting thru the edges and it seems the IsSelected works, too (it reacts twice edge 1 and 9).. but for the EdgePoints i get weird results. the first result makes sense (edge 1: point 1 and 3) but why does it return point 1 and 3 also for edge 9??

• On 11/10/2014 at 13:01, xxxxxxxx wrote:

Could it be, EdgePoints() delivers the point index on the polygon?
I'm not sure and haven't tried it. And it's getting a bit late for today for me to do so.
Doesn't the CPolygon contain the vertex indeces directly (a, b, c ,d)?

• On 11/10/2014 at 13:04, xxxxxxxx wrote:

yes, it does. but i need to get the indices for the points which build the selected edges only. not the whole polygon. i'll keep on trying :)

• On 11/10/2014 at 13:07, xxxxxxxx wrote:

Yes, I understood that. Via the index received from GetEdgePoints() you should be able to choose between a, b, c and d (like in the example on PolyInfo struct). I probably should have elaborated a bit further. Sorry.

Once more I'm sorry, not like in the example. But in a similar way. I'd expect the indeces from GetEdgePoints() to correspond directly to a, b, c and d.

• On 11/10/2014 at 13:09, xxxxxxxx wrote:

ah, wait, i guess i understand now. is it that EdgePoints can only return 0 to 3

• On 11/10/2014 at 13:11, xxxxxxxx wrote:

I think so. But in order to be sure, I'd either have to try or to look it up in the code. I can't do so before Monday, so I'd recommend, you try yourself.
If this is the case, I'll add it to my notes for SDK doc improvement...

• On 11/10/2014 at 13:12, xxxxxxxx wrote:

ok. thank you so far.

• On 11/10/2014 at 14:53, xxxxxxxx wrote:

So, i wen on using the PolyInfo Example. Still some weird results.
based on the image i posted previously i get points 1->3 which is correct, and for the other edge between points 7->5 i get 6->4. if i choose other edges the thing continues with wrong results.

why are the results different from the indices i get in cinema when checking the vertices in the structure manager??

any help is appreciated.

``````		for (int i=0; i<fcnt; i++)
{
PolyInfo *pli = neighbor.GetPolyInfo(i);

for (int side=0; side<4; side++)
{
switch (side)
{
}

if (selection->IsSelected(edge))
{
GePrint("Selected Edge: "+LongToString(edge)+" - Points "+LongToString(p1)+"->"+LongToString(p2));
}
}
}
``````

• On 12/10/2014 at 09:29, xxxxxxxx wrote:

I was a bit quick with my assumptions yesterday, sorry

Check the following code (it it's not complete, it assumes you a poly selection pBSPoly) :

``````  LONG pcnt = g_objPoly->GetPointCount();
LONG fcnt = g_objPoly->GetPolygonCount();
LONG p1, p2;

if (pBSPoly) {  // starting with a polygon selection here
SelectionChanger * pSC = SelectionChanger::Alloc();
if (pSC->InitFromSelection(pBSPoly, Mpolygons, g_objPoly)) {
Neighbor neighbor;
if (neighbor.Init(pcnt, fadr, fcnt, nullptr)) {
BaseSelect* pBSEdges = pSC->GetEdgeS();    // convert polygon selection into an edge selection
// NOTE: edges are multiple times in this pBSEdges (once for each poly, idxPoly*4+idxEdge)
// NOTE 2: BSEdges is owned by pSC (I think)
if (pBSEdges) {
for (int idxPolys = 0; idxPolys < fcnt; idxPolys++) {
PolyInfo *pPI = neighbor.GetPolyInfo(idxPolys);
// From example SDK docs PolyInfo struct:
int idxSide;
for (idxSide = 0; idxSide < 4; idxSide++) { // test all 4 sides of a polygon
// only proceed if edge has not already been processed
// and edge really exists (for triangles side 2 from c..d does not exist as c==d)

String nfo = "";
switch (idxSide) {
} // switch (idxSide...
if (pBSEdges->IsSelected((4 * idxPolys) + idxSide)) {
nfo = "selected";
} // if (pBSEdges->....
GePrint("Edge " + LongToString(p1) + "->" + LongToString(p2) + ": " + nfo);
} // for (idxSide...
} // for (idxPolys
} // if (pBSEdges)...
} // if (neighbor...
SelectionChanger::Free(pSC);
} // if (pSC->...
} else { // if (pBSPoly
// Handle error: SELECTION NOT CONVERTED
}
``````

One more note:

``````fadr->EdgePoints(idxEdges, p1, p2);
``````

You were always addressing the first polygon with this.

I hope this helps.

• On 12/10/2014 at 11:16, xxxxxxxx wrote:

I think he's looking for the point index#s Andreas.
You're code produces edge index#s. Which he needs to be converted into point index#s and their global positions.

While I'm watching Football on T.V. I've rolled my own EdgesToPoints code to do this. Without using the neighbor class.
But I'd like to see how it's done using the neighbor class too.

I can post my no-neighbors class version if you like.
But I'm also interested in seeing how to do it using the neighbor class.

-ScottA

• On 12/10/2014 at 12:25, xxxxxxxx wrote:

Scott, my code prints point indeces. Its using the edge index only for selection checking.

Would you mind, to post your code here as well?
It's always good to have several ways to accomplish something, so anybody can chose the one fitting his needs best.

• On 12/10/2014 at 12:59, xxxxxxxx wrote:

Maybe I'm doing something wrong?
Your code is not returning the correct point index#s. Or the correct selected edge ID#s for me.

Here's the way I'm doing it without the neighbor class:

``````//This code grabs the selected edges from an edge selection tag
//Then it get's their Index# and global positions of the points in them
//Then it selects those points on the object

Bool SimplePlugin::Execute(BaseDocument *doc)
{
PolygonObject *obj = (PolygonObject* ) doc->GetActiveObject();
if(!(obj && (obj->GetType() == Opolygon))) return FALSE;

CPolygon *polygons = obj->GetPolygonW();
Vector *points = obj->GetPointW();

//The edge selection tag holding the selected edges data
SelectionTag *etag = NULL;
etag = (SelectionTag* )obj->GetTag(Tedgeselection, 0);
if(!etag) return FALSE;

//Get the selected edges from the selection tag
BaseSelect *EdgeS = etag->GetBaseSelect();
if(EdgeS->GetCount() < 1) return FALSE;

//Create an empty selection array to hold the points we will eventually select later on
BaseSelect *PointS = BaseSelect::Alloc();

//The number of edges = the number of polygons * 4
LONG maxEdgeCnt = obj->GetPolygonCount()*4;

for(LONG i=0; i<maxEdgeCnt; i++)
{
if( EdgeS->IsSelected(i) )
{
//These edge index #s are not the same thing as point index #s
LONG edge = i;
LONG PolyInd = int(edge/4);

//The polygon's ID#
CPolygon Polygon = polygons[PolyInd];

//The edge within the each polygon( 0-3 )
LONG PolyEdgeInd = edge-4*(PolyInd);

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

//Get the Index# and the global positions of the points in the PointS BaseSelect array
//We only need to get a or b
LONG seg=0,a,b,i;
while(PointS->GetRange(seg++,MAXLONGl,&a,&b))
{
for (i=a; i<=b; ++i)
{
Vector gPPos = points[a] * obj->GetMg();
GePrint( "index# "+ LongToString(a) +" "+ RealToString(gPPos.x) + " " + RealToString(gPPos.y) + " " + RealToString(gPPos.z) );
}
}

//Select the points in the editor view using the PointS array if desired
PointS->CopyTo(obj->GetPointS());

//Free the memory used
BaseSelect::Free(PointS);

return TRUE;
}
``````

It seems to work pretty good.
But I just cranked it out while yelling at my T.V.
I don't know how well this will handle N-Gons or Tris.

-ScottA

• On 12/10/2014 at 13:11, xxxxxxxx wrote:

Scott,
can you give me a simple example, where my code fails? Because here it's working nicely. But perhaps my setup is too simple, and it only returns correct values by chance.
You did notice though, that it starts with a poly selection?
I'd really be interested to get mine fixed, if it contains any bugs.
Even if I like your solution better, it's more straight forward.