#include "vtkPolyDataToImageStencil.h" #include "vtkLinearExtrusionFilter.h" #include "vtkImageStencil.h" #include "vtkImageStencilData.h" #include "vtkImageData.h" #include "vtkPolyData.h" #include "vtkPoints.h" #include "vtkIdList.h" #include "vtkSmartPointer.h" #include "vtkMatrixToLinearTransform.h" #include "vtkTransformPolyDataFilter.h" #include "vtkMatrix4x4.h" #include "vtkTesting.h" #include "vtkDataSetMapper.h" #include "vtkActor.h" #include "vtkRenderer.h" #include "vtkRenderWindow.h" #include "vtkRenderWindowInteractor.h" #include "vtkInteractorStyleTrackballCamera.h" #include "vtkTriangleFilter.h" #include "vtkPolygon.h" #include "vtkUnstructuredGrid.h" #include "vtkGeometryFilter.h" #include "vtkShrinkFilter.h" #include "vtkIdList.h" #include "vtkStructuredGrid.h" #include "vtkCellArray.h" #include "vtkPolyDataMapper.h" #include "vtkStructuredGridOutlineFilter.h" #include "vtkStructuredGridGeometryFilter.h" #include "vtkShrinkFilter.h" #include "vtkDoubleArray.h" #include "vtkPointData.h" #include "vtkCellData.h" #include "vtkArray.h" #include "vtkPlane.h" #include "vtkCutter.h" #include "vtkProperty.h" #include "vtkDataSet.h" #include "vtkFloatArray.h" #include "vtkLookupTable.h" #include "vtkLegendBoxActor.h" #include "vtkGlyph3D.h" #include "vtkConeSource.h" #include "vtkScalarBarActor.h" #include "vtkArrowSource.h" #include "vtkCellCenters.h" #include "vtkAxesActor.h" #include "vtkOrientationMarkerWidget.h" #include "vtkCamera.h" #include "vtkArrayCalculator.h" #include "vtkImplicitPlaneWidget2.h" #include "vtkImplicitPlaneRepresentation.h" #include "vtkCommand.h" #include "vtkTextActor.h" #include "vtkContourFilter.h" #include "vtkCellDataToPointData.h" #include "vtkPolyDataNormals.h" #include "vtkAssignAttribute.h" #include "vtkDataSetAttributes.h" #include "vtkTextProperty.h" #include "vtkCallbackCommand.h" #include "vtkStreamTracer.h" #include "math.h" int main() { double wx = 3; double wy = 2; double wz = 4; const int imax = 5; const int jmax = 10; const int kmax = 10; int noCells = imax*jmax*kmax; double dx[imax]; double dy[jmax]; double dz[kmax]; for (unsigned i=0; i < imax; i++){ dx[i]=wx/imax; } for (unsigned j=0; j < jmax; j++){ dy[j]=wy/jmax; } for (unsigned k=0; k < kmax; k++){ dz[k]=wz/kmax; } int noPoints = (imax+1)*(jmax+1)*(kmax+1); vtkPoints *points = vtkPoints::New(); points->Allocate(noPoints,noPoints); double x0 = 0; double y0 = 0; double z0 = 0; int pointCounter = -1; for (unsigned iz = 0; iz < kmax+1; iz++){ for (unsigned iy = 0; iy < jmax+1; iy++){ for (unsigned ix = 0; ix < imax+1; ix++){ pointCounter++; double xC = x0+dx[ix-1]*ix; double yC = y0+dy[iy-1]*iy; double zC = z0+dz[iz-1]*iz; points->InsertPoint(pointCounter,xC,yC,zC); } } } vtkStructuredGrid *sGrid = vtkStructuredGrid::New(); sGrid->SetDimensions(imax+1,jmax+1,kmax+1); sGrid->SetPoints(points); points->Delete(); vtkCellCenters *gridCellCenters = vtkCellCenters::New(); gridCellCenters->SetInput(sGrid); vtkStructuredGridOutlineFilter *sGridOF = vtkStructuredGridOutlineFilter::New(); sGridOF->SetInput(sGrid); vtkPolyDataMapper *gridMapper = vtkPolyDataMapper::New(); gridMapper->SetInput(sGridOF->GetOutput()); vtkActor *gridActor = vtkActor::New(); gridActor->SetMapper(gridMapper); vtkFloatArray *v = vtkFloatArray::New(); v->SetNumberOfComponents(3); for (unsigned iz = 0; iz < kmax; iz++){ for (unsigned iy = 0; iy < jmax; iy++){ for (unsigned ix = 0; ix < imax; ix++){ T->InsertNextValue(iz); v->InsertNextTuple3(ix,iy,iz); } } } sGrid->GetCellData()->SetVectors(v); vtkArrowSource *arrow = vtkArrowSource::New(); vtkGlyph3D *glyph = vtkGlyph3D::New(); glyph->SetInput(gridCellCenters->GetOutput()); glyph->SetSourceConnection(arrow->GetOutputPort()); glyph->SetScaleModeToScaleByVector(); glyph->SetColorModeToColorByVector(); glyph->SetScaleFactor(0.1); glyph->Update(); vtkPolyDataMapper *glyphMapper = vtkPolyDataMapper::New(); glyphMapper->SetInputConnection(glyph->GetOutputPort()); vtkActor *glyphActor = vtkActor::New(); glyphActor->SetMapper(glyphMapper); // Kamera vtkCamera *camera = vtkCamera::New(); camera->SetPosition(-8,8,-8); camera->SetFocalPoint(sGrid->GetCenter()); // Rendering vtkRenderer *ren1 = vtkRenderer::New(); ren1->AddActor(gridActor); ren1->AddActor(glyphActor); ren1->SetBackground( 0, 0, 0 ); ren1->SetActiveCamera(camera); vtkRenderWindow *renWin = vtkRenderWindow::New(); renWin->AddRenderer( ren1 ); renWin->SetSize( 1024, 768 ); renWin->Render(); vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New(); iren->SetRenderWindow(renWin); iren->Initialize(); iren->Start(); // --------------------------------------------------------------------------- gridMapper->Delete(); gridActor->Delete(); ren1->Delete(); iren->Delete(); renWin->Delete(); return 0; }