📄 vtk.cpp
字号:
#include "stdafx.h"
//自行完成了线的实现
//#include "vtkRenderer.h"
//#include "vtkRenderWindow.h"
//#include "vtkRenderWindowInteractor.h"
//#include "vtkSphereSource.h"
//#include "vtkPolyDataMapper.h"
//#include "vtkActor.h"
//#include "vtkConeSource.h"
//#include "vtkGlyph3D.h"
//#include "vtkCamera.h"
//#include "vtkPoints.h"
//#include "vtkPolyData.h"
//#include "vtkProperty.h"
//#include <vtkCellArray.h>
//
//void main( int argc, char *argv[] )
//{
// // create the rendering objects
// vtkRenderer *ren1 = vtkRenderer::New();
// vtkRenderWindow *renWin = vtkRenderWindow::New();
// renWin->AddRenderer(ren1);
// vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
// iren->SetRenderWindow(renWin);
//
// // create the pipline, ball and spikes
// vtkSphereSource *sphere = vtkSphereSource::New();
// //sphere->SetThetaResolution(7);
// //sphere->SetPhiResolution(7);
//
// vtkPoints *points=vtkPoints::New();
// /*points->InsertNextPoint( 10.48, -187.4, -126.9);
// points->InsertNextPoint( 12.81, -187.7, -126.4 );
// points->InsertNextPoint( 15.44 ,-187.9, -125.9 );
// points->InsertNextPoint( 18.02, -187.7, -125.7 );
// points->InsertNextPoint( 20.23, -187.6, -125.5 );
// points->InsertNextPoint( 21.46, -189.3, -124.2 );
// points->InsertNextPoint( 20.05, -190, -123.9 );
// points->InsertNextPoint( 18.6, -190.1, -124.1 );
// points->InsertNextPoint( 17.14, -190.3, -124.1 );
// points->InsertNextPoint( 15.66, -190.4, -124.3 );*/
// //points->InsertNextPoint(10,15,0.799);
// //points->InsertNextPoint(10,16,0.89);
// //points->InsertNextPoint(10,17,0.99);
// //points->InsertNextPoint(10,18,0.79);
// //points->InsertNextPoint(10,19,0.89);
// points->InsertPoint(0,10,15,0.799);
// points->InsertPoint(1,10,16,0.75);
// points->InsertPoint(2,10,17,0.9);
// points->InsertPoint(3,10,18,0.99);
//
// vtkCellArray *line = vtkCellArray ::New();
// line->InsertNextCell(5);
// line->InsertCellPoint(0);
// line->InsertCellPoint(1);
// line->InsertCellPoint(2);
// line->InsertCellPoint(3);
// line->InsertCellPoint(4);
// vtkPolyData *model=vtkPolyData::New();
// model-> SetPoints( points);
// model->SetLines(line);
// //vtkGlyph3D *glyph = vtkGlyph3D::New();
// //glyph->SetInput(model);
// //glyph->SetSource(sphere->GetOutput());//用输入的数据源来作为轮廓;
// //glyph->SetVectorModeToUseNormal();//采用向量操作
// //glyph->SetScaleModeToScaleByVector();
// //glyph->SetScaleFactor(0.25);
// vtkPolyDataMapper *spikeMapper = vtkPolyDataMapper::New();
// //spikeMapper->SetInput(glyph->GetOutput());
// spikeMapper->SetInput(model);
// vtkActor *spikeActor = vtkActor::New();
// spikeActor->SetMapper(spikeMapper);
// spikeActor-> GetProperty() ->SetDiffuseColor( 1 ,0 ,0);
//
//
// ren1->AddActor(spikeActor);
// ren1->SetBackground(1,1,1);
// renWin->SetSize(600,400);
//
// renWin->Render();
// ren1->GetActiveCamera()->Zoom(1.4);
// renWin->Render();
//
// iren->Start();
//
// ren1->Delete();
// renWin->Delete();
// iren->Delete();
// sphere->Delete();
// //glyph->Delete();
// spikeMapper->Delete();
// spikeActor->Delete();
//}
//
////点集绘曲面
//#include "vtkMath.h"
//#include "vtkShortArray.h"
//#include "vtkStructuredPoints.h"
//#include "vtkRenderer.h"
//#include "vtkRenderWindow.h"
//#include "vtkRenderWindowInteractor.h"
//#include "vtkContourFilter.h"
//#include "vtkPolyDataMapper.h"
//#include "vtkActor.h"
//#include "vtkPointData.h"
//#include "vtkProperty.h"
//
//float Pr = 10.0; // The Lorenz parameters
//float b = 2.667;
//float r = 28.0;
//float x, y, z; // starting (and current) x, y, z
//float h = 0.01; // integration step size
//int resolution=600; // slice resolution
//int iter = 10000000; // number of iterations
//float xmin = -30.0; // x, y, z range for voxels
//float xmax = 30.0;
//float ymin = -30.0;
//float ymax = 30.0;
//float zmin = -10.0;
//float zmax = 60.0;
//
//int randomMode = 1;
//float xIncr, yIncr, zIncr;
//short *slice;
//
////#include "SaveImage.h"
//
//void main( int argc, char *argv[] )
//{
// int i, j;
// float xx, yy, zz;
// short xxx, yyy, zzz;
// int sliceSize;
//
// short *s;
// void options(int, char**);
// int numPts, index;
//
// // take a stab at an integration step size
// xIncr = resolution / (xmax - xmin);
// yIncr = resolution / (ymax - ymin);
// zIncr = resolution / (zmax - zmin);
//
// printf ("The Lorenz Attractor\n");
// printf (" Pr = %f\n", Pr);
// printf (" b = %f\n", b);
// printf (" r = %f\n", r);
// printf (" integration step size = %f\n", h);
// printf (" slice resolution = %d\n", resolution);
// printf (" # of iterations = %d\n", iter);
// printf (" specified range:\n");
// printf (" x: %f, %f\n", xmin, xmax);
// printf (" y: %f, %f\n", ymin, ymax);
// printf (" z: %f, %f\n", zmin, zmax);
//
// x = vtkMath::Random(xmin, xmax);
// y = vtkMath::Random(ymin, ymax);
// z = vtkMath::Random(zmin, zmax);
// printf (" starting at %f, %f, %f\n", x, y, z);
//
// // allocate memory for the slices
// sliceSize = resolution * resolution;
// numPts = sliceSize * resolution;
// vtkShortArray *scalars = vtkShortArray::New();
// s = scalars->WritePointer(0, numPts);
// for (i = 0; i < numPts; i++) s[i] = 0;
//
// printf (" integrating...\n");
// for (j = 0; j < iter; j++)
// {
// // integrate to next time step
// xx = x + h * Pr * (y - x);
// yy = y + h * (x * (r - z) - y);
// zz = z + h * (x * y - (b * z));
//
// x = xx; y = yy; z = zz;
//
// // calculate voxel index
// if (x < xmax && x > xmin && y < ymax && y > ymin && z < zmax && z > zmin)
// {
// xxx = (short) ((float)(xx - xmin) * xIncr);
// yyy = (short) ((float)(yy - ymin) * yIncr);
// zzz = (short) ((float)(zz - zmin) * zIncr);
// index = xxx + yyy*resolution + zzz*sliceSize;
// s[index] += 1;
// }
// }
//
// vtkStructuredPoints *volume = vtkStructuredPoints::New();
// volume->GetPointData()->SetScalars(scalars);
// volume->SetDimensions(resolution,resolution,resolution);
// volume->SetOrigin(xmin,ymin,zmin);
// volume->SetSpacing((xmax-xmin)/resolution, (ymax-ymin)/resolution,
// (zmax-zmin)/resolution);
//
// printf (" contouring...\n");
// // do the graphics dance
// vtkRenderer *renderer = vtkRenderer::New();
// vtkRenderWindow *renWin = vtkRenderWindow::New();
// renWin->AddRenderer(renderer);
//
// vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
// iren->SetRenderWindow(renWin);
//
// // create iso-surface
// vtkContourFilter *contour = vtkContourFilter::New();
// contour->SetInput(volume);
// contour->SetValue(0,50);
//
// // create mapper
// vtkPolyDataMapper *mapper = vtkPolyDataMapper::New();
// mapper->SetInput(contour->GetOutput());
// mapper->ScalarVisibilityOff();
//
// // create actor
// vtkActor *actor = vtkActor::New();
// actor->SetMapper(mapper);
// actor->GetProperty()->SetColor(0.6863,0.9333,0.9333);
//
// renderer->AddActor(actor);
// renderer->SetBackground(1,1,1);
//
// renWin->SetSize(300,300);
//
// // interact with data
// renWin->Render();
//
// // SAVEIMAGE( renWin );
//
// iren->Start();
//
// // Clean up
// scalars->Delete();
// volume->Delete();
// renderer->Delete();
// renWin->Delete();
// iren->Delete();
// contour->Delete();
// mapper->Delete();
// actor->Delete();
//}
////一个四边形的产生
//#include "vtkActor.h"
//#include "vtkCamera.h"
//#include "vtkCullerCollection.h"
//#include "vtkPlaneSource.h"
//#include "vtkPolyDataMapper.h"
//#include "vtkRenderWindow.h"
//#include "vtkRenderer.h"
//#include "vtkStripper.h"
//#include "vtkCellArray.h"
//#include "vtkTriangleFilter.h"
//#include "vtkRenderWindowInteractor.h"
//#include "vtkClipPolyData.h"
//#include "vtkCylinder.h"
//#include "vtkProperty.h"
//
//int main( int argc, char *argv[] )
//{
// // create a rendering window and both renderers
// vtkRenderer *ren1 = vtkRenderer::New();
// ren1->GetCullers()->InitTraversal();
// //ren1->RemoveCuller(ren1->GetCullers()->GetNextItem());
// vtkRenderWindow *renWindow = vtkRenderWindow::New();
// renWindow->AddRenderer(ren1);
//
// vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
// iren->SetRenderWindow(renWindow);
//
// vtkPoints *points=vtkPoints::New();
// points-> SetNumberOfPoints(8);
//
// points-> InsertPoint (0, 574977491, 328641875, 0.000000);
// points-> InsertPoint (1, 580271124, 323671875, 0.000000);
// points-> InsertPoint (2, 604170252, 323921875, 0.000000);
// points-> InsertPoint (3, 598828062, 328911875, 0.000000);
// points-> InsertPoint (4, 33753574.977491, 18753286.439951, 0.000000);
// points-> InsertPoint (5, 33753580.271124, 18753236.772283, 0.000000);
// points-> InsertPoint (6, 33753604.170252, 18753239.195716, 0.000000);
// points-> InsertPoint (7, 33753598.828062, 18753289.148470, 0.000000);
// /*
// points-> InsertPoint (0, 200.057, 200.028, 0.000000);
// points-> InsertPoint (1, 200.058, 200.023, 0.000000);
// points-> InsertPoint (2, 200.060, 200.023, 0.000000);
// points-> InsertPoint (3, 200.059, 200.028, 0.000000);
// */
// vtkCellArray *cellArray=vtkCellArray::New();
// cellArray-> InsertNextCell (8);
// cellArray-> InsertCellPoint( 0);
// cellArray-> InsertCellPoint( 1);
// cellArray-> InsertCellPoint( 2);
// cellArray-> InsertCellPoint( 3);
// cellArray-> InsertCellPoint( 4);
// cellArray-> InsertCellPoint( 5);
// cellArray-> InsertCellPoint( 6);
// cellArray-> InsertCellPoint( 7);
//
// vtkPolyData *polyData=vtkPolyData::New();
// polyData-> SetPoints (points);
// polyData-> SetPolys (cellArray);
//
//
//
//
// // The mapper is responsible for pushing the geometry into the graphics
// // library. It may also do color mapping, if scalars or other attributes
// // are defined.
//
// vtkPolyDataMapper *cylinderMapper=vtkPolyDataMapper::New();
// cylinderMapper-> SetInput (polyData);
//
// // The actor is a grouping mechanism: besides the geometry (mapper), it
// // also has a property, transformation matrix, and/or texture map.
// // Here we set its color and rotate it -22.5 degrees.
// vtkActor *cylinderActor=vtkActor::New();
// cylinderActor-> SetMapper (cylinderMapper);
// cylinderActor-> GetProperty()-> SetColor (0.2,0.5,0.2);
// cylinderActor-> RotateX (30.0);
// cylinderActor-> RotateY (-45.0);
// cylinderActor-> GetProperty()-> SetOpacity( 1.0);
// cylinderActor-> GetProperty()-> SetAmbient( 0.5);
// cylinderActor-> GetProperty()-> SetDiffuse( 0.6);
// cylinderActor-> GetProperty()-> SetSpecular( 0.6 );
// cylinderActor-> GetProperty()-> SetSpecularPower( 10.0);
// cylinderActor-> GetProperty()-> SetColor( 1.0, 0.2, 0.4);
//
// ren1->AddActor(cylinderActor);
//
// renWindow->SetSize(500,500);
// ren1->SetBackground(0.1, 0.2, 0.4);
//
// renWindow->Render();
// ren1->GetActiveCamera()->Zoom (1.5);
// renWindow->Render();
//
// iren->Start();
//
// ren1->Delete();
// renWindow->Delete();
// return 1;
//}
//
//#include "vtkActor.h"
//#include "vtkCamera.h"
//#include "vtkCullerCollection.h"
//#include "vtkPlaneSource.h"
//#include "vtkPolyDataMapper.h"
//#include "vtkRenderWindow.h"
//#include "vtkRenderer.h"
//#include "vtkStripper.h"
//#include "vtkTimerLog.h"
//#include "vtkTriangleFilter.h"
//#include "vtkRenderWindowInteractor.h"
//#include "vtkLineSource.h"
//#include "vtkRenderWindowInteractor.h"
//#include "vtkProperty.h"
//#include "math.h"
//#include "stdio.h"
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -