[vtkusers] Symmetry questions
David Doria
daviddoria+vtk at gmail.com
Mon Feb 8 18:42:38 EST 2010
Try this:
I didn't really look at the logic, but it compiles and doesn't crash.
#include <vtkPolyDataMapper.h>
#include <vtkActor.h>
#include <vtkRenderWindow.h>
#include <vtkRenderer.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkPolyData.h>
#include <vtkTransform.h>
#include <vtkTransformPolyDataFilter.h>
#include <vtkAppendPolyData.h>
#include <vtkCylinderSource.h>
#include <vtkSmartPointer.h>
int main (int argc, char *argv[])
{
vtkSmartPointer<vtkCylinderSource> source =
vtkSmartPointer<vtkCylinderSource>::New();
source->SetCenter(1,1,1);
source->Update();
// Determine which axes are flipped
bool xFlipped=true;
bool yFlipped=true;
//bool yFlipped=false;
// Add a new vtkAppendData to deal with the new symmetrical data
vtkSmartPointer<vtkAppendPolyData> appendData =
vtkSmartPointer<vtkAppendPolyData>::New();
// Add the source data
appendData->AddInput(source->GetOutput());
if(xFlipped)
{
// Add a vtkTranform to apply symmetry to the dataset
vtkSmartPointer<vtkTransform> pTranslationX =
vtkSmartPointer<vtkTransform>::New();
pTranslationX->Translate(1.0, 0.0, 0.0);
// Apply translation filter to data for given symmetry
vtkSmartPointer<vtkTransformPolyDataFilter> pTransformFilter1 =
vtkSmartPointer<vtkTransformPolyDataFilter>::New();
pTransformFilter1->SetInputConnection(source->GetOutputPort());
pTransformFilter1->SetTransform(pTranslationX);
pTransformFilter1->Update();
// Create a vtkPolyData set and add it to the vtkAppendPolyData for the
symmetrical data
vtkSmartPointer<vtkPolyData> pData1 =
pTransformFilter1->GetOutput();
appendData->AddInput(pData1);
}
if(yFlipped)
{
vtkSmartPointer<vtkTransform> pTranslationY =
vtkSmartPointer<vtkTransform>::New();
pTranslationY->Translate(0.0, 1.0, 0.0);
// Apply translation filter to data for given symmetry
vtkSmartPointer<vtkPolyData> pTempData =
appendData->GetOutput();
vtkSmartPointer<vtkTransformPolyDataFilter> pTransformFilter2 =
vtkSmartPointer<vtkTransformPolyDataFilter>::New();
pTransformFilter2->SetInputConnection(source->GetOutputPort());
pTransformFilter2->SetTransform(pTranslationY);
pTransformFilter2->Update();
// Create a vtkPolyData set and add it to the vtkAppendPolyData for the
symmetrical data
vtkPolyData * pData1 = pTransformFilter2->GetOutput();
appendData->AddInput(pData1);
}
appendData->Update();
vtkPolyData* result = appendData->GetOutput();
vtkSmartPointer<vtkPolyDataMapper> mapper =
vtkSmartPointer<vtkPolyDataMapper>::New();
mapper->SetInput(result);
vtkSmartPointer<vtkActor> actor =
vtkSmartPointer<vtkActor>::New();
actor->SetMapper(mapper);
vtkSmartPointer<vtkRenderer> renderer =
vtkSmartPointer<vtkRenderer>::New();
vtkSmartPointer<vtkRenderWindow> renderWindow =
vtkSmartPointer<vtkRenderWindow>::New();
renderWindow->AddRenderer(renderer);
// Add Actor to renderer
renderer->SetBackground(1,1,1); // Background color white
// Add Actor to renderer
renderer->AddActor(actor);
vtkSmartPointer<vtkRenderWindowInteractor> interactor =
vtkSmartPointer<vtkRenderWindowInteractor>::New();
interactor->SetRenderWindow(renderWindow);
interactor->Start();
return 0;
}
Thanks,
David
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20100208/ddf70fa0/attachment.htm>
More information about the vtkusers
mailing list