Use VTK to draw massive discrete points (This method uses vertex Genie and glsl)

Source: Internet
Author: User
In the non-grid method, ttttttttt draws discrete points. If there are many points, they cannot be represented by small balls. In my test, if the number of small balls exceeds one hundred, the speed is too slow to bear. The solution is to use the dot genie or glsl coloring language.

# Include "vtkcamera. H"
# Include "vtkrenderwindow. H"
# Include "vtkrenderwindowindowinteractor. H"
# Include "vtkinteractorstyleswitch. H"
# Include "vtkpolydata. H"
# Include "vtkpointsource. H"
# Include "vtkrenderer. H"
# Include "vtkelevationfilter. H"
# Include "vtkpointspritemapper. H"
# Include "vtkimagegaussiansource. H"
# Include "vtkmath. H"
# Include "vtkactor. H"
# Include "vtkdebugleaks. H"
# Include "vtkproperty. H"
# Include "vtksmartpointer. H"
# Include "vtkpolydata. H"
# Include "vtkpoints. H"
# Include "vtkcellarray. H"
# Include "vtkfloatarray. H"
# Include "vtkpointdata. H"

// VTK Testing
# Include "vtktestutilities. H"
# Include "vtkregressiontestimage. H"
# Include "vtkspheresource. H"
# Include "vtkappendpolydata. H"

# Include <vtksys/systemtools. hxx>
# Include <vtkstd/string>

// # Define sprites_on
// # Define spheres_on
# Define use_glsl 0
# Define use_pointsprites 1

//---------------------------------------------------------------------------
// Bool setenv (const char * Name, const char * val, bool overwrite );
//---------------------------------------------------------------------------
Int main (INT argc, char * argv [])
{
 
//
// We are loading shaders from a custom materials repository, tell
// The vtkxmlshader Loading Code to search here.
//
// Setenv ("user_materials_dirs", resourcedir. c_str (), true );

//////////////////////////////////////// ////////
//
// An array of point sprite sphere glyphs
//
//////////////////////////////////////// ////////
Const double rows = 10;
Const double numspheres = rows * Rows;
Const double ascaling = 0.1;
Const double bscaling = 1.0-ascaling;

Vtkpolydata * sprites = vtkpolydata: New ();
Vtkpoints * points = vtkpoints: New ();
Vtkcellarray * Verts = vtkcellarray: New ();
Vtkfloatarray * sizes = vtkfloatarray: New ();

points-> setnumberofpoints (numspheres);
sizes-> setnumberoftuples (numspheres);
sizes-> setnumberofcomponents (1 );
Verts-> allocate (numspheres, numspheres);
sprites-> setpoints (points);
sprites-> setverts (Verts );
sizes-> setname ("pointsizes");
sprites-> getpointdata ()-> addarray (sizes );
//
for (INT y = 0; y for (INT x = 0; x vtkidtype id = y * Rows + X;
points-> setpoint (ID, X, Y, 0.0 );
sizes-> setvalue (ID, ascaling + bscaling * (double) ID/numspheres);
Verts-> insertnextcell (1, & ID );
}< BR >}

//
// Colour sprites
//
Vtkelevationfilter * spritecolour = vtkelevationfilter: New ();
Spritecolour-> setinput (sprites );
Spritecolour-> setlowpoint (0.0, 0.0, 0.0 );
Spritecolour-> sethighpoint (rows, rows, 0.0 );

Vtkpointspritemapper * spritemapper = vtkpointspritemapper: New ();

Spritemapper-> setrendermodetopointsprite ();
Spritemapper-> setblendmodetoocclude ();
Spritemapper-> setdefapointpointsize (64 );
Spritemapper-> setquadraticpointdistanceattenuation (1.0, 0.1, 0.0 );
 
Spritemapper-> setparticipant leimagefilename ("D:/aaa.png ");
Spritemapper-> setparticipant image (null );
Spritemapper-> setinputconnection (spritecolour-> getoutputport ());

// Create actor and set sprite mapper
Vtkactor * spriteactor = vtkactor: New ();
Spriteactor-> setmapper (spritemapper );

//////////////////////////////////////// ////////
//
// An array of spheres to go alongside sprites
//
//////////////////////////////////////// ////////
Vtkspheresource * spheresource = vtkspheresource: New ();
Vtkappendpolydata * sphereappend = vtkappendpolydata: New ();
For (INT y = 0; y <rows; y ++ ){
For (INT x = 0; x <rows; X ++ ){
Int id = y * Rows + X;
Spheresource-> setcenter (X, Y, 1.0 );
Spheresource-> setradius (ascaling + bscaling * (double) ID/numspheres)/2.0 );
Spheresource-> setthetaresolution (32 );
Spheresource-> setphiresolution (16 );
Spheresource-> Update ();
Vtkpolydata * poly = vtkpolydata: New ();
Poly-> deepcopy (spheresource-> getoutput ());
Sphereappend-> addinput (poly );
Poly-> Delete ();
}
}

//
// Colour spheres
//
Vtkelevationfilter * spherecolour = vtkelevationfilter: New ();
Spherecolour-> setinputconnection (sphereappend-> getoutputport ());
Spherecolour-> setlowpoint (0.0, 0.0, 0.0 );
Spherecolour-> sethighpoint (rows, rows, 0.0 );

//
// Polydata mapper
//
Vtkpolydatamapper * spheremapper = vtkpolydatamapper: New ();
Spheremapper-> setinputconnection (spherecolour-> getoutputport ());

//
// Spheremapper actor
//
Vtkactor * sphereactor = vtkactor: New ();
Sphereactor-> setmapper (spheremapper );

//////////////////////////////////////// ////////
// Setup Renderer etc
//////////////////////////////////////// ////////
Vtkrenderer * Ren = vtkrenderer: New ();
// # Ifdef sprites_on
Ren-> addactor (spriteactor );
// # Endif
// # Ifdef spheres_on
// Ren-> addactor (sphereactor );
// # Endif
Const double distance = 1.75;
Ren-> setbackground (0.0, 0.0, 0.0 );
Ren-> getactivecamera ()-> setposition (distance * (rows + 1.0), distance * (rows + 1.0), 0.5 );
Ren-> getactivecamera ()-> setfocalpoint (rows/2.0, rows/2.0, 0.5 );
Ren-> getactivecamera ()-> setroll (45.0 );
Ren-> resetcameraclippingrange ();

Vtkrenderwindow * renwin = vtkrenderwindow: New ();
Renwin-> setsize (512,512 );
Renwin-> addrenderer (ren );

Vtkrenderwindowindowinteractor * iren = vtkrenderwindowindowinteractor: New ();
Iren-> setrenderwindow (renwin );
Vtkinteractorstyleswitch * Is = vtkinteractorstyleswitch: New ();
Iren-> setinteractorstyle (is );
Is-> setcurrentstyletotrackballcamera ();

Renwin-> render ();

Iren-> Start ();
 

 
Return 1;
}

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.