⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 vtk.cpp

📁 VTK入门样例(种类齐全)
💻 CPP
📖 第 1 页 / 共 3 页
字号:
//	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 "vtkTimerLog.h"
//#include "vtkTriangleFilter.h"
//#include "vtkRenderWindowInteractor.h"
//#include "vtkLineSource.h"
//#include "vtkRenderWindowInteractor.h"
//#include "vtkProperty.h"
//#include "math.h"
//#include "stdio.h"
//#include <time.h>

//float position[262]={
//	449032.91,	  25672.88	,
//	446812.22,	  20872.62	,
//	441046.13,	  24301.65	,
//	442942.38,	  18966.99	,
//	447097.09,	  25305.72	,
//	455161.53,	  14141.05	,
//	439310.41,	  19010.13	,
//	438085.88,	  14687.51	,
//	447918.84,	  19331.86	,
//	448568.91,	  23915.72	,
//	448556.94,	  24516.78	,
//	447969.53,	  23300.76	,
//	448080.38,	  23922.83	,
//	447625.66,	  23534.48	,
//	447583.59,	  24001.22	,
//	448196.25,	  23967.58	,
//	448065.91,	  23351.34,
//	447652.34,	  23415.57,	
//	447590.91,	  23425.53	,
//	447560.75,	  22965.00	,
//	444567.25,	  20616.15	,
//	445489.19,	  20622.57	,
//	446665.25,	  20594.70	,
//	446221.41,	  20372.95	,
//	447598.94,	  24023.19,
//	448675.44,	  23297.16,
//	446977.47,	  23473.02,
//	445187.38,	  20611.10,
//	445767.19,	  20587.66,	
//	446063.81,	  20633.31,	
//	447243.06,	  20516.51,	
//	444539.75,	  20021.57,	
//	445154.16,	  19985.01,	
//	445421.09,	  20045.41	,
//	446003.72,	  19954.35,	
//	446619.63,	  19939.35,	
//	446972.06,	  20584.35,	
//	445661.75,	  20387.19,	
//	446956.72,	  20022.31,	
//	446640.25,	  19952.29,	
//	447267.22,	  19771.13	,
//	447868.81,	  19747.50,	
//	445720.31,	  19427.35,	
//	446618.78,	  19360.17	,
//	447225.66,	  19337.28,	
//	446902.34,	  18809.72,	
//	447504.47,	  19045.30,	
//	447796.25,   19316.93,	
//	447811.50,	  18764.76	,
//	445124.47,	  17870.97,	
//	446481.50,	  18436.89,	
//	447050.63,	  18428.50,	
//	445741.94,	  17671.55,	
//	445837.44,	  13905.08,	
//	447962.75,	  24528.27	,
//	449189.38,	  24467.26,	
//	447560.06,	  24620.25,	
//	447956.88,	  23930.37	,
//	449185.97,	  23889.81,	
//	449247.81,	  23891.65,	
//	449247.44,	  23299.05	,
//	447560.72,	  19999.17,	
//	447908.56,	  20363.66,	
//	445479.41,	  18825.18,	
//	446664.53,	  18778.88,	
//	446736.16,	  19042.18,	
//	447294.94,	  19075.03	,
//	447963.16,	  19010.89,	
//	445195.84,	  18647.83,	
//	446071.63,	  18186.48,	
//	447302.50,	  18457.19	,
//	445792.47,	  18002.41,	
//	446403.75,	  18029.52,	
//	446358.44,	  18213.15	,
//	445768.75,	  17460.21,	
//	446344.69,	  17630.00,	
//	447035.75,	  17199.80,	
//	447662.41,	  17044.38	,
//	446073.97,	  21154.50,	
//	448162.28,	  23403.33,	
//	447588.28,	  20853.76,	
//	447806.34,	  20238.74	,
//	445197.16,	  18467.71,	
//	445393.31,	  18368.95	,
//	446507.66,	  17820.55,	
//	446133.78,	  25965.40,	
//	446332.00,	  19388.50,	
//	448556.00,	  23159.25	,
//	445480.00,	  17411.25,	
//	446780.00,	  22292.50	,
//	446876.00,	  17925.75,	
//	448544.00,	  18076.00,	
//	452636.00,	  24847.00,	
//	452540.00,	  18854.75,	
//	441136.00,	  16604.50	,
//	448192.00,	  22166.00,	
//	448776.00,	  23806.50,	
//	445324.00,	  19709.25,	
//	447492.00,	  23740.00,	
//	453584.00,	  13169.00	,
//	449958.31,	  24757.82,	
//	448872.00,	  20965.75,	
//	438336.00,	  13498.75,	
//	447264.06,	  23153.60,	
//	444084.00,	  13813.00,	
//	444872.00,	  11753.00	,
//	439792.938,	  25224.596 ,
//	439923.438,   24520.045,
//	439688.563,   23580.645 ,
//	438749.188,   24128.629 ,
//	440888.906,   24754.895 ,
//	440627.969,   22510.771 ,
//	439975.625,   21545.275 ,
//	438670.875,   12960.195 ,
//	438827.469,   13168.950 ,
//	438775.281,   12490.494 ,
//	440993.313,   13090.667 ,
//	450335.125,   13873.501 ,
//	453153.313,   12855.817,
//	454510.219,   20397.119 ,
//	454640.719,   20475.402 ,
//	452213.906,   19718.662,
//	454327.563,   24859.273 ,
//	454223.188,   24154.723,
//	451796.406,   23189.227 ,
//	451300.625,   12960.195 ,
//	443602.750,   24206.910 ,
//	443602.750,   23267.510 ,
//	441958.781,   20527.590 ,
//	438000,      26000 ,
//	455200,      11700 ,
//};
//int main()
//{	
//
//	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);
//	///////////////////////////
//
//	vtkLineSource *line[131];
//	vtkPolyDataMapper *lineMapper[131];
//	vtkActor *lineActor[131];
//
//	srand(time(NULL)) ;
//	for(int i=0;i<131;i++)
//	{
//		line[i]=vtkLineSource::New(); 
//		line[i]->SetPoint1(position[2*i] ,position[2*i+1], 0);
//		if (i<129)
//			line[i]->SetPoint2(position[2*i] ,position[2*i+1], 5000);
//		else
//			line[i]->SetPoint2(position[2*i] ,position[2*i+1], 10000);
//		line[i]->SetResolution(20);
//
//		lineMapper[i] = vtkPolyDataMapper::New();

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -