#ifndef Initial_opengl
#define Initial_opengl
#include <vtkAutoInit.h>
Vtk_module_init (VTKRENDERINGOPENGL)
Vtk_module_init (Vtkinteractionstyle)
#endif
#include <iostream>
using namespace Std;
#include <vtkVersion.h>
#include <vtkPolyData.h>
#include <vtkProperty.h>
#include <vtkMath.h>
#include <vtkSmartPointer.h>
#include <vtkPolyDataMapper.h>
#include <vtkActor.h>
#include <vtkRenderWindow.h>
#include <vtkRenderer.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkImageData.h>
#include <vtkGreedyTerrainDecimation.h>
#include <vtkInteractorStyleTrackballCamera.h>
#include <vtkInteractionWidgetsModule.h>
void Myshow (vtkgreedyterraindecimation* aninput)
{
Vtksmartpointer<vtkpolydatamapper> amapper=vtksmartpointer<vtkpolydatamapper>::new ();
Amapper->setinputconnection (Aninput->getoutputport ());
Amapper->scalarvisibilityon ();
Vtksmartpointer<vtkactor> anactor=vtksmartpointer<vtkactor>::new ();
Anactor->setmapper (Amapper);
Anactor->getproperty ()->setinterpolationtoflat ();
Anactor->getproperty ()->edgevisibilityon ();
Anactor->getproperty ()->setedgecolor (1,0,0);
Vtksmartpointer<vtkrenderer> ren1=vtksmartpointer<vtkrenderer>::new ();
Vtksmartpointer<vtkrenderwindow> renwin=vtksmartpointer<vtkrenderwindow>::new ();
Ren1->addactor (Anactor);
Ren1->resetcamera ();
Ren1->setbackground (1,1,1);
Renwin->addrenderer (REN1);
Renwin->setsize (512,512);
Vtksmartpointer<vtkrenderwindowinteractor> iren=vtksmartpointer<vtkrenderwindowinteractor>::new ();
Vtksmartpointer<vtkinteractorstyletrackballcamera> style=vtksmartpointer< Vtkinteractorstyletrackballcamera>::new ();
Iren->setrenderwindow (Renwin);
Iren->setinteractorstyle (style);
Iren->start ();
}
int main ()
{
Vtksmartpointer<vtkimagedata> image=vtksmartpointer<vtkimagedata>::new ();
Image->setdimensions (120,120,1);
Image->allocatescalars (vtk_unsigned_char,1);
int dims[3];
double max=sqrt (dims[0]*dims[0]+dims[1]*dims[1]);
Image->getdimensions (dims);
Double r=100;//spherical radius
Double r=0;//any x, y coordinate point, and the distance to the (0,0) point
Double r2=r*r;
Double RCROWN=DIMS[0]/2;
Double rcrown2=rcrown*rcrown;//ball Crown radius squared
Double hmax2=r*r-rcrown2;//the maximum arc vector height squared
Double hmax=r-sqrt (HMAX2);//maximum arc vector height
for (double i=0;i<dims[0];i++)
{
for (double j=0;j<dims[1];j++)
{
unsigned char* pixel=static_cast<unsigned char*> (Image->getscalarpointer (i,j,0));
Double x= (I-DIMS[0]/2), y= (J-DIMS[1]/2);
R2=x*x+y*y;
R=SQRT (R2);
if (R<rcrown)
Do not know why, to add a maximum arc vector height Hmax, in order to get the correct crown, is probably the coordinate direction of the problem it
PIXEL[0]=SQRT (R*R-R2)-(R-hmax) +hmax;
Else
Pixel[0]=hmax;
}
}
Vtksmartpointer<vtkgreedyterraindecimation>decimation=vtksmartpointer<vtkgreedyterraindecimation>: : New ();
Decimation->setinputdata (image);
Decimation->update ();
Visualization of
Myshow (decimation);
return 0;
}
VTK Beginner One, a Mesh from vtkimagedata-ball crown