Use VTK to select a vertex on the screen and add a tag

Source: Internet
Author: User

Split in Earth-rock damProgramIn the development process, because the constraints must be added in the form of visualization, You need to select a vertex and add the mark, but in the actual development process found

After marking is added, the flash of the current image is marked during the rotation of the dam because the deep calculation method of the marking and dam unit is different.

You can use setresoveconindepolytopoyoffset () to solve this problem. Unfortunately, this function is invalid here, for example.CodeAs follows:

Extern int X11, y11;
Extern crect rect;

Vtkrenderer * Ren;
Vtkrenderwindow * renwin;
Vtkmycellpicker * picker;
Vtkfollower * myactor;
// Vtkpointpicker * picker;
Vtkactor2d * actor2d;
Class vtkmycallback: Public vtkcommand
{
Public:
Static vtkmycallback * New ()
{Return New vtkmycallback ;}
Virtual void execute (vtkobject * caller, unsigned long, void *)
{

Vtkrenderwindowindowinteractor * IR = (vtkrenderwindowindowinteractor *) (caller );
Int x = ir-> geteventposition () [0];
Int y = ir-> geteventposition () [1];


Picker-> pick (X, Y, 0.0, Ren );
Vtkassemblypath * Path = NULL;
Path = picker-> getpath ();
If (! Path)
{
Return;
}
Double CEN [3];
// (Vtkactor *) (path-> getfirstnode ()-> getviewprop ()-> getmapper ()-> getcenter (CEN );
// Double POS [3];
// Ren-> getactivecamera ()-> getposition (POS );
// Vtkmapper * Mm = (vtkactor *) (path-> getfirstnode ()-> getviewprop ()-> getmapper ();
// Picker-> insertline (Pos, CEN, 0.01, path, (vtkprop3d *) (path-> getfirstnode ()-> getviewprop (), mm );
Int id = picker-> getcellid ();

Cstring STR;
Str. Format ("% d", ID );
// Afxmessagebox (STR );
If (path! = NULL)
{
(Vtkactor *) (path-> getfirstnode ()-> getviewprop ()-> getproperty ()-> setcolor (1.0, 0.0, 0.0 );

}
Vtkcell * mycell = (vtkactor *) (path-> getfirstnode ()-> getviewprop ()-> getmapper ()-> getinput ()-> getcell (ID );
Vtkpoints * mypoints = mycell-> getpoints ();
Int nid = mypoints-> getnumberofpoints ();
Int idnum = 0;
Double D = 0.0;
Double d_v = 1000000;
For (INT I = 0; I <NID; I ++)
{
Double M [4];
M [3] = 1.0;
Mypoints-> getpoint (I, m );
Ren-> setworldpoint (M [0], M [1], M [2], M [3]);
Ren-> worldtodisplay ();
Double ss [3];
Ren-> getdisplaypoint (SS );

D = (ss [0]-x) * (ss [0]-x) + (ss [1]-y) * (ss [1]-y );

If (d {< br> d_v = D;
idnum = I;
}< br> double dd [4];
dd [3] = 1.0;
mypoints-> getpoint (idnum, DD);
myactor-> setposition (dd);

// Ren-> setworldpoint (dd );
// Ren-> worldtodisplay ();
// Ren-> getdisplaypoint (dd );
// Actor2d-> setdisplayposition (Dd [0], Dd [1]);
 



Renwin-> render ();
//
Cstring str1;
Str1.format ("% d", idnum );
// Afxmessagebox (str1 );

//
}


};

Vtkmycallback * mycommand;

Cvtk: cvtk ()
{
// Connect each VTK object to a channel in the constructor

/// // Read data

// Connect each VTK object to a channel in the constructor
//////////////////////////////////

// Change the color and ID of the selected Vertex

Vtkspheresource ** geometry = new vtkspheresource * [5];
Vtkpolydatamapper ** mapper = new vtkpolydatamapper * [5];
Vtkactor ** actor = new vtkactor * [5];

Ren = vtkrenderer: New ();

Renwin = vtkrenderwindow: New ();

Picker = new vtkmycellpicker ();
// Picker = vtkpointpicker: New ();
Picker-> settolerance (0.001 );

Vtkpoints * point = vtkpoints: New ();
Point-> setnumberofpoints (3 );
Point-> insertpoint (0, 0.0, 0.0, 0.0 );
Point-> insertpoint (1, 10.0, 0.0, 0.0 );
Point-> insertpoint (2, 0.0, 10.0, 0.0 );

Vtkcellarray * cell = vtkcellarray: New ();
Vtkidtype num [] = {0, 1, 2 };
Cell-> insertnextcell (3, num );

Vtkpolydata * Data = vtkpolydata: New ();
Data-> setpoints (point );
Data-> setpolys (cell );

Vtkpolydatamapper * polymapper = vtkpolydatamapper: New ();
Polymapper-> setinput (data );
Vtkactor * vtkactor = vtkactor: New ();
Vtkactor-> setmapper (polymapper );
Vtkactor-> getproperty ()-> setcolor (0.8, 0.1, 0.0 );

Ren-> addactor (vtkactor );

Vtktextmapper * textmapper = vtktextmapper: New ();
Textmapper-> setinput ("#");
Actor2d = vtkactor2d: New ();
Actor2d-> setmapper (textmapper );
// Actor2d-> setdisplayposition (100,100 );
Ren-> addactor2d (actor2d );


Vtkvectortext * mytext = vtkvectortext: New ();
Mytext-> settext ("#");
Vtkpolydatamapper * mmapper = vtkpolydatamapper: New ();
Mmapper-> setinput (mytext-> getoutput ());
Mmapper-> setresolvecoincidenttopologytopolygonoffset ();
Myactor = vtkfollower: New ();
Myactor-> setmapper (mmapper );

Myactor-> getproperty ()-> setcolor (0.0, 1.0, 0.0 );

Ren-> addactor (myactor );

For (Int J = 0; j <5; j ++)
{

Geometry [J] = vtkspheresource: New ();
Geometry [J]-> setthetaresolution (16 );
Geometry [J]-> setphiresolution (8 );
Geometry [J]-> setradius (0.005 );
Geometry [J]-> setcenter (J * 0.1 );

Mapper [J] = vtkpolydatamapper: New ();
Mapper [J]-> setinput (geometry [J]-> getoutput ());

Actor [J] = vtkactor: New ();
Actor [J]-> setmapper (mapper [J]);
Actor [J]-> visibilityoff ();

Ren-> addactor (actor [J]);

 


}

Mycommand = vtkmycallback: New ();

Iren = vtkrenderwindowindowinteractor: New ();

Style = new vtkmystyle ();
Vtkinteractorstyletrackballcamera * style1 = vtkinteractorstyletrackballcamera: New ();
Iren-> setinteractorstyle (style1 );
Iren-> disable ();

Iren-> setrenderwindow (renwin );

Renwin-> addrenderer (ren );
 

 

 





/////////////////////////////////

 

 

 
}

Cvtk ::~ Cvtk ()
{
Renwin-> Delete ();
// Renderer-> Delete ();
// Iren-> Delete ();
// Cone-> Delete ();
// Conemapper-> Delete ();
// Coneactor-> Delete ();
}

Void cvtk: beginrendeon (cstatic * astatic)
{
Crect rect;
Astatic-> getclientrect (& rect );
Renwin-> setsize (rect. Width (), rect. Height ());
// Renwin-> setwindowid (astatic-> m_hwnd );
Renwin-> setparentid (astatic-> m_hwnd); // key code 1: Set the parent window
// Iren-> Start ();
Renwin-> render (); // key code 2: Start the rendering and start the interactive device.

}

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.