#include <vtkTubeFilter.h>
#include <vtkImplicitBoolean.h>
#include <vtkImplicitFunctionCollection.h>
+////
+#include <vtkFollower.h>
+#include <vtkObjectFactory.h>
+#include <vtkDataSet.h>
+#include <vtkRenderWindow.h>
+////
+//==================================================================
+// class : VISU_UnScaledActor
+// purpose :
+//==================================================================
+class VISU_UnScaledActor: public vtkFollower
+{
+
+public:
+
+ vtkTypeMacro(VISU_UnScaledActor,vtkFollower);
+ static VISU_UnScaledActor *New();
+
+
+ void SetCenter(float *);
+ virtual void SetSize(int theSize);
+ virtual void Render(vtkRenderer *theRenderer);
+ virtual float *GetBounds();
+
+protected:
+ VISU_UnScaledActor();
+ ~VISU_UnScaledActor(){}
+ float myCenter[3];
+ int mySize;
+};
+
+////
+
+vtkStandardNewMacro(VISU_UnScaledActor);
+
+//====================================================================
+// function: VISU_UnScaledActor
+// purpose:
+//====================================================================
+VISU_UnScaledActor::VISU_UnScaledActor()
+{
+ for (int i=0; i<3; ++i){
+ myCenter[i]=0.;
+ }
+ mySize=24;
+}
+//====================================================================
+// function: SetCenter
+// purpose:
+//====================================================================
+void VISU_UnScaledActor::SetCenter(float *pC)
+{
+ for (int i=0; i<3; ++i){
+ myCenter[i]=pC[i];
+ }
+}
+//====================================================================
+// function:GetBounds
+// purpose:
+//====================================================================
+float* VISU_UnScaledActor::GetBounds()
+{
+ Superclass::GetBounds();
+ //
+ for (int i=0; i<3; ++i){
+ Bounds[2*i]=myCenter[i];
+ Bounds[2*i+1]=myCenter[i];
+ }
+ return Bounds;
+}
+//====================================================================
+// function:Render
+// purpose:
+//====================================================================
+void VISU_UnScaledActor::Render(vtkRenderer *theRenderer)
+{
+ if(theRenderer){
+ float P[2][3] = {{-1.0, -1.0, 0.0},{+1.0, +1.0, 0.0}};
+ theRenderer->ViewToWorld(P[0][0],P[0][1],P[0][2]);
+ theRenderer->ViewToWorld(P[1][0],P[1][1],P[1][2]);
+ float aWorldDiag = sqrt((P[1][0]-P[0][0])*(P[1][0]-P[0][0])+
+ (P[1][1]-P[0][1])*(P[1][1]-P[0][1])+
+ (P[1][2]-P[0][2])*(P[1][2]-P[0][2]));
+ int* aSize = theRenderer->GetRenderWindow()->GetSize();
+ float aWinDiag = sqrt(float(aSize[0]*aSize[0]+aSize[1]*aSize[1]));
+ vtkDataSet* aDataSet = GetMapper()->GetInput();
+ float aLength = aDataSet->GetLength();
+ float aPrecision = 1.e-3;
+ float anOldScale = GetScale()[0];
+ float aScale =
+ mySize*aWorldDiag/aWinDiag/aLength*sqrt(float(aSize[0])/float(aSize[1]));
+
+ SetOrigin(myCenter);
+ //
+ if(fabs(aScale - anOldScale)/aScale > aPrecision){
+ SetScale(aScale);
+ }
+ }
+ vtkFollower::Render(theRenderer);
+
+}
+//====================================================================
+// function:SetSize
+// purpose:
+//====================================================================
+void VISU_UnScaledActor::SetSize(int theSize)
+{
+ mySize = theSize;
+}
+////
static float DistanceToPlane(const float x[3],
const float n[3],
const float p0[3]);
:
vtkPolyDataSourceWidget()
{
- this->State = VISU_ImplicitFunctionWidget::Start;
- this->EventCallbackCommand->SetCallback(VISU_ImplicitFunctionWidget::ProcessEvents);
+ State = VISU_ImplicitFunctionWidget::Start;
+ EventCallbackCommand->SetCallback(VISU_ImplicitFunctionWidget::ProcessEvents);
- this->NormalToXAxis = 0;
- this->NormalToYAxis = 0;
- this->NormalToZAxis = 0;
+ NormalToXAxis = 0;
+ NormalToYAxis = 0;
+ NormalToZAxis = 0;
- this->HandleMoveEvent = true;
- this->HandleLeftButtonEvent = true;
- this->HandleMiddleButtonEvent = false;
- this->HandleRightButtonEvent = false;
+ HandleMoveEvent = true;
+ HandleLeftButtonEvent = true;
+ HandleMiddleButtonEvent = false;
+ HandleRightButtonEvent = false;
// Build the representation of the widget
//
- this->Plane = vtkPlane::New();
- this->Plane->SetNormal(0,0,1);
- this->Plane->SetOrigin(0,0,0);
+ Plane = vtkPlane::New();
+ Plane->SetNormal(0,0,1);
+ Plane->SetOrigin(0,0,0);
//
- this->myDistance = 10.;
- this->myPlane2 = vtkPlane::New();
- this->myPlane2->SetNormal(0.,0.,-1.);
- this->myPlane2->SetOrigin(0,0,this->myDistance);
+ myDistance = 10.;
+ myPlane2 = vtkPlane::New();
+ myPlane2->SetNormal(0.,0.,-1.);
+ myPlane2->SetOrigin(0,0,myDistance);
//
- this->myImplicitFunction = vtkImplicitBoolean::New();
- this->myImplicitFunction->SetOperationType(VTK_UNION);
+ myImplicitFunction = vtkImplicitBoolean::New();
+ myImplicitFunction->SetOperationType(VTK_UNION);
//
- this->Box = vtkImageData::New();
- this->Box->SetDimensions(2,2,2);
- this->Outline = vtkOutlineFilter::New();
- this->Outline->SetInput(this->Box);
- this->OutlineMapper = vtkPolyDataMapper::New();
- this->OutlineMapper->SetInput(this->Outline->GetOutput());
- this->OutlineActor = vtkActor::New();
+ Box = vtkImageData::New();
+ Box->SetDimensions(2,2,2);
+ Outline = vtkOutlineFilter::New();
+ Outline->SetInput(Box);
+ OutlineMapper = vtkPolyDataMapper::New();
+ OutlineMapper->SetInput(Outline->GetOutput());
+ OutlineActor = vtkActor::New();
this->OutlineActor->SetMapper(this->OutlineMapper);
this->OutlineActor->PickableOff();
this->OutlineTranslation = 0;
this->myCutActor2->SetMapper(this->myCutMapper2);
this->Edges = vtkFeatureEdges::New();
+ Edges->SetColoring(0);
this->Edges->SetInput(this->Cutter->GetOutput());
- this->EdgesTuber = vtkTubeFilter::New();
- this->EdgesTuber->SetInput(this->Edges->GetOutput());
- this->EdgesTuber->SetNumberOfSides(12);
this->EdgesMapper = vtkPolyDataMapper::New();
- this->EdgesMapper->SetInput(this->EdgesTuber->GetOutput());
+ this->EdgesMapper->SetInput(this->Edges->GetOutput());
this->EdgesActor = vtkActor::New();
this->EdgesActor->SetMapper(this->EdgesMapper);
- this->Tubing = 1; //control whether tubing is on
+ EdgesActor->GetProperty()->SetLineWidth(4.);
+ EdgesActor->GetProperty()->SetColor(0., .5, .7);
// Create the + plane normal
this->LineSource = vtkLineSource::New();
this->ConeSource = vtkConeSource::New();
this->ConeSource->SetResolution(12);
- this->ConeSource->SetAngle(25.0);
+ this->ConeSource->SetAngle(20.);
this->ConeMapper = vtkPolyDataMapper::New();
this->ConeMapper->SetInput(this->ConeSource->GetOutput());
- this->ConeActor = vtkActor::New();
+ this->ConeActor = VISU_UnScaledActor::New();
this->ConeActor->SetMapper(this->ConeMapper);
+ ConeActor->SetSize(36);
+ ConeActor->SetCenter(ConeSource->GetCenter());
// Create the - plane normal
this->LineSource2 = vtkLineSource::New();
this->ConeSource2 = vtkConeSource::New();
this->ConeSource2->SetResolution(12);
- this->ConeSource2->SetAngle(25.0);
+ this->ConeSource2->SetAngle(20.);
this->ConeMapper2 = vtkPolyDataMapper::New();
this->ConeMapper2->SetInput(this->ConeSource2->GetOutput());
- this->ConeActor2 = vtkActor::New();
+ this->ConeActor2 = VISU_UnScaledActor::New();
this->ConeActor2->SetMapper(this->ConeMapper2);
+ ConeActor2->SetSize(36);
+ ConeActor2->SetCenter(ConeSource2->GetCenter());
// Create the origin handle
this->Sphere = vtkSphereSource::New();
this->Sphere->SetPhiResolution(8);
this->SphereMapper = vtkPolyDataMapper::New();
this->SphereMapper->SetInput(this->Sphere->GetOutput());
- this->SphereActor = vtkActor::New();
+ this->SphereActor = VISU_UnScaledActor::New();
this->SphereActor->SetMapper(this->SphereMapper);
+ SphereActor->SetSize(36);
+ SphereActor->SetCenter(Sphere->GetCenter());
this->Transform = vtkTransform::New();
// Set up the initial properties
this->CreateDefaultProperties();
+
}
//==================================================================
// function: ~
myCutActor2->Delete();
this->Edges->Delete();
- this->EdgesTuber->Delete();
this->EdgesMapper->Delete();
this->EdgesActor->Delete();
return;
}
}
-
+ //
+ vtkCamera *pCamera=CurrentRenderer->GetActiveCamera();
+ pCamera->SetParallelProjection(1);
+ //
this->myImplicitFunction->AddFunction(this->Plane);
this->myImplicitFunction->AddFunction(this->myPlane2);
this->LineSource->SetPoint2(p2);
this->ConeSource->SetCenter(p2);
this->ConeSource->SetDirection(normal);
+ ConeActor->SetCenter(p2);
p2[0] = origin[0] - 0.30 * d * normal[0];
p2[1] = origin[1] - 0.30 * d * normal[1];
this->LineSource2->SetPoint2(p2);
this->ConeSource2->SetCenter(p2);
this->ConeSource2->SetDirection(normal);
+ ConeActor2->SetCenter(p2);
// Set up the position handle
this->Sphere->SetCenter(origin);
+ SphereActor->SetCenter(origin);
- // Control the look of the edges
- if ( this->Tubing ) {
- this->EdgesMapper->SetInput(this->EdgesTuber->GetOutput());
- }
- else {
- this->EdgesMapper->SetInput(this->Edges->GetOutput());
- }
+ this->EdgesMapper->SetInput(this->Edges->GetOutput());
}
//==================================================================
// function:SizeHandles
//==================================================================
void VISU_ImplicitFunctionWidget::SizeHandles()
{
- float radius = this->vtk3DWidget::SizeHandles(1.35);
-
- this->ConeSource->SetHeight(2.0*radius);
- this->ConeSource->SetRadius(radius);
- this->ConeSource2->SetHeight(2.0*radius);
- this->ConeSource2->SetRadius(radius);
-
- this->Sphere->SetRadius(radius);
-
- this->EdgesTuber->SetRadius(0.25*radius);
+ // float radius =
+ this->vtk3DWidget::SizeHandles(1.35);
}
//==================================================================
// function:PrintSelf
os << indent << "Normal To Z Axis: "
<< (this->NormalToZAxis ? "On" : "Off") << "\n";
- os << indent << "Tubing: " << (this->Tubing ? "On" : "Off") << "\n";
os << indent << "Outline Translation: "
<< (this->OutlineTranslation ? "On" : "Off") << "\n";
os << indent << "Draw Plane: " << (this->DrawPlane ? "On" : "Off") << "\n";