[vtkusers] vtkImplicitFunction question
alex dowson
alexdowson at hotmail.com
Mon Jan 6 06:48:05 EST 2014
Hi
I am trying to do tricky part as match implicit surface with parametric surface but not getting proper result.
First I create implicit surface using vtkPlane->vtkSampleFunction and create parametric surface using vtkPlaneSource. Then apply transformation to both as rotate 20 degree in x and rotate 30 degree in Y. Both output should be similar but it’s different. I am not able to figure out reason.
As you can see in picture red plane is produced using vtkSampleFunction and white one is using vtkPlaneSource.
I attached screen shot and code if any one can explain me why it is different.
code
#include "vtkSmartPointer.h"
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkInteractorStyleTrackballCamera.h"
#include "vtkPolyDataMapper.h"
#include "vtkActor.h"
#include "vtkContourFilter.h"
#include "vtkSampleFunction.h"
#include "vtkPlane.h"
#include "vtkProperty.h"
#include "vtkTransformPolyDataFilter.h"
#include "vtkTransform.h"
#include "vtkOutlineFilter.h"
#include "vtkPlaneSource.h"
int main()
{
vtkSmartPointer<vtkRenderer> renderer = vtkSmartPointer<vtkRenderer>::New();
vtkSmartPointer<vtkRenderWindow> renderWindow = vtkSmartPointer<vtkRenderWindow>::New();
renderWindow->SetSize(640,480);
renderWindow->AddRenderer(renderer);
vtkSmartPointer<vtkRenderWindowInteractor> renderInteractor = vtkSmartPointer<vtkRenderWindowInteractor>::New();
renderInteractor->SetRenderWindow(renderWindow);
vtkSmartPointer< vtkInteractorStyleTrackballCamera> style = vtkSmartPointer<vtkInteractorStyleTrackballCamera>::New();
renderInteractor->SetInteractorStyle(style);
vtkSmartPointer<vtkTransform> xform = vtkSmartPointer<vtkTransform>::New();
xform->Identity();
xform->RotateX(20);
xform->RotateY(30);
vtkSmartPointer<vtkPlane> plane = vtkSmartPointer<vtkPlane>::New();
plane->SetNormal(1,0,0);
plane->SetTransform(xform);
// Sample the function
vtkSmartPointer<vtkSampleFunction> sample = vtkSmartPointer<vtkSampleFunction>::New();
sample->SetSampleDimensions(10,10,10);
sample->SetImplicitFunction(plane);
double xmin = -0.5, xmax=0.5, ymin=-0.5, ymax=0.5, zmin=-0.5, zmax=0.5;
sample->SetModelBounds(xmin, xmax, ymin, ymax, zmin, zmax);
// Create the 0 isosurface
vtkSmartPointer<vtkContourFilter> contours = vtkSmartPointer<vtkContourFilter>::New();
contours->SetInputConnection(sample->GetOutputPort());
contours->SetValue(0,0);
contours->Update();
vtkSmartPointer<vtkPolyDataMapper> mapperSample = vtkSmartPointer<vtkPolyDataMapper>::New();
mapperSample->SetInputConnection(contours->GetOutputPort());
vtkSmartPointer<vtkActor> actorSample = vtkSmartPointer<vtkActor>::New();
actorSample->SetMapper(mapperSample);
renderer->AddActor(actorSample);
vtkSmartPointer<vtkPlaneSource> planeSource = vtkSmartPointer<vtkPlaneSource>::New();
planeSource->SetNormal(1,0,0);
vtkSmartPointer<vtkTransformPolyDataFilter> xformFilter =
vtkSmartPointer<vtkTransformPolyDataFilter>::New();
xformFilter->SetInput(planeSource->GetOutput());
xformFilter->SetTransform(xform);
vtkSmartPointer<vtkPolyDataMapper> xformMapper= vtkSmartPointer<vtkPolyDataMapper>::New();
xformMapper->SetInput(xformFilter->GetOutput());
vtkSmartPointer<vtkActor> xformActor = vtkSmartPointer<vtkActor>::New();
xformActor->SetMapper(xformMapper);
renderer->AddActor(xformActor);
// create outline
vtkSmartPointer<vtkOutlineFilter> outline = vtkSmartPointer<vtkOutlineFilter>::New();
outline->SetInputConnection(xformFilter->GetOutputPort());
// map it to graphics primitives
vtkSmartPointer<vtkPolyDataMapper> outlineMapper = vtkSmartPointer<vtkPolyDataMapper>::New();
outlineMapper->SetInputConnection(outline->GetOutputPort());
// create an actor for it
vtkSmartPointer<vtkActor> outlineActor = vtkSmartPointer<vtkActor>::New();
outlineActor->SetMapper(outlineMapper);
outlineActor->GetProperty()->SetColor(0,0,0);
renderer->AddActor(outlineActor);
renderer->SetBackground(.1,.2,.3);
renderer->ResetCamera();
renderWindow->Render();
renderInteractor->Start();
return EXIT_SUCCESS;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20140106/a61a7ca8/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Untitled.png
Type: image/png
Size: 48221 bytes
Desc: not available
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20140106/a61a7ca8/attachment.png>
More information about the vtkusers
mailing list