#include "vtkEllipseRepresent2D.h"
#include "vtkActor2D.h"
#include "vtkAssemblyPath.h"
#include "vtkCellArray.h"
#include "vtkCoordinate.h"
#include "vtkCursor2D.h"
#include "vtkGlyph2D.h"
#include "vtkInteractorObserver.h"
#include "vtkLeaderActor2D.h"
#include "vtkLine.h"
#include "vtkMath.h"
#include "vtkObjectFactory.h"
#include "vtkPoints.h"
#include "vtkPolyDataAlgorithm.h"
#include "vtkPolyDataMapper2D.h"
#include "vtkProperty2D.h"
#include "vtkRenderer.h"
#include "vtkTextMapper.h"
#include "vtkTextProperty.h"
#include "vtkTransform.h"
#include "vtkWindow.h"
#include <stdlib.h>
#include <time.h>
#include <qdebug.h>
#include <vtkRenderWindow.h>
vtkStandardNewMacro(vtkEllipseRepresent2D);
vtkCxxSetObjectMacro(vtkEllipseRepresent2D, Property, vtkProperty2D);
vtkCxxSetObjectMacro(vtkEllipseRepresent2D, SelectedProperty, vtkProperty2D);
vtkCxxSetObjectMacro(vtkEllipseRepresent2D, TextProperty, vtkTextProperty);
#define VTK_CIRCLE_RESOLUTION 64
//----------------------------------------------------------------------
vtkEllipseRepresent2D::vtkEllipseRepresent2D()
{
// It's best to have a small tolerance
this->Tolerance = 3;
// Initialize state
this->InteractionState = vtkAffineRepresentation::Outside;
// The width of the widget
this->DisplayText = 1;
this->CircleWidth = static_cast<int>(0.75 * 100);
this->AxesWidth = static_cast<int>(0.60 * 100);
this->CurrentWidth = 0.0;
this->CurrentRadius = 0.0;
this->CurrentAxesWidth = 0.0;
// Keep track of transformations
this->DisplayOrigin[0] = this->DisplayOrigin[1] = this->DisplayOrigin[2] = 0.0;
this->Origin[0] = this->Origin[1] = this->Origin[2] = 0.0;
// Create properties
this->CreateDefaultProperties();
// Text label
this->TextMapper = vtkTextMapper::New();
this->TextMapper->SetTextProperty(this->TextProperty);
this->TextMapper->SetInput("");
this->TextActor = vtkActor2D::New();
this->TextActor->SetMapper(this->TextMapper);
this->TextActor->VisibilityOn();
this->HBoxPoints = vtkPoints::New();
this->HBoxPoints->SetNumberOfPoints(4);
this->HBoxCellArray = vtkCellArray::New();
this->HBoxCellArray->AllocateEstimate(1, 4);
this->HBoxCellArray->InsertNextCell(5);
this->HBoxCellArray->InsertCellPoint(0);
this->HBoxCellArray->InsertCellPoint(1);
this->HBoxCellArray->InsertCellPoint(2);
this->HBoxCellArray->InsertCellPoint(3);
this->HBoxCellArray->InsertCellPoint(0);
this->HBox = vtkPolyData::New();
this->HBox->SetPoints(this->HBoxPoints);
this->HBox->SetLines(this->HBoxCellArray);
this->HBoxMapper = vtkPolyDataMapper2D::New();
this->HBoxMapper->SetInputData(this->HBox);
this->HBoxActor = vtkActor2D::New();
this->HBoxActor->SetMapper(this->HBoxMapper);
this->HBoxActor->VisibilityOff();
this->HBoxActor->SetProperty(this->SelectedProperty);
this->HBoxActor->GetProperty()->SetOpacity(0.22);
// Circle
this->CirclePoints = vtkPoints::New();
this->CirclePoints->SetNumberOfPoints(VTK_CIRCLE_RESOLUTION);
this->CircleCellArray = vtkCellArray::New();
this->CircleCellArray->AllocateEstimate(1, VTK_CIRCLE_RESOLUTION + 1);
this->Circle = vtkPolyData::New();
this->Circle->SetPoints(this->CirclePoints);
this->Circle->SetLines(this->CircleCellArray);
this->CircleMapper = vtkPolyDataMapper2D::New();
this->CircleMapper->SetInputData(this->Circle);
this->CircleActor = vtkActor2D::New();
this->CircleActor->SetMapper(this->CircleMapper);
this->CircleActor->SetProperty(this->Property);
this->HCirclePoints = vtkPoints::New();
this->HCircleCellArray = vtkCellArray::New();
this->HCircleCellArray->AllocateEstimate(1, VTK_CIRCLE_RESOLUTION + 1);
this->HCircle = vtkPolyData::New();
this->HCircle->SetPoints(this->HCirclePoints);
this->HCircle->SetLines(this->HCircleCellArray);
this->HCircleMapper = vtkPolyDataMapper2D::New();
this->HCircleMapper->SetInputData(this->HCircle);
this->HCircleActor = vtkActor2D::New();
this->HCircleActor->SetMapper(this->HCircleMapper);
this->HCircleActor->VisibilityOff();
this->HCircleActor->SetProperty(this->SelectedProperty);
// Translation axes
this->XAxis = vtkLeaderActor2D::New();
this->XAxis->GetPositionCoordinate()->SetCoordinateSystemToDisplay();
this->XAxis->GetPosition2Coordinate()->SetCoordinateSystemToDisplay();
this->XAxis->SetArrowStyleToFilled();
this->XAxis->SetProperty(this->Property);
this->XAxis->SetMaximumArrowSize(12);
this->YAxis = vtkLeaderActor2D::New();
this->YAxis->GetPositionCoordinate()->SetCoordinateSystemToDisplay();
this->YAxis->GetPosition2Coordinate()->SetCoordinateSystemToDisplay();
this->YAxis->SetArrowStyleToFilled();
this->YAxis->SetProperty(this->Property);
this->YAxis->SetMaximumArrowSize(12);
this->HXAxis = vtkLeaderActor2D::New();
this->HXAxis->GetPositionCoordinate()->SetCoordinateSystemToDisplay();
this->HXAxis->GetPosition2Coordinate()->SetCoordinateSystemToDisplay();
this->HXAxis->SetArrowStyleToFilled();
this->HXAxis->SetProperty(this->SelectedProperty);
this->HXAxis->SetMaximumArrowSize(12);
this->HXAxis->VisibilityOff();
this->HYAxis = vtkLeaderActor2D::New();
this->HYAxis->GetPositionCoordinate()->SetCoordinateSystemToDisplay();
this->HYAxis->GetPosition2Coordinate()->SetCoordinateSystemToDisplay();
this->HYAxis->SetArrowStyleToFilled();
this->HYAxis->SetProperty(this->SelectedProperty);
this->HYAxis->SetMaximumArrowSize(12);
this->HYAxis->VisibilityOff();
// Transformation matrix
this->CurrentTransform = vtkTransform::New();
this->TotalTransform = vtkTransform::New();
this->CurrentTranslation[0] = 0.0;
this->CurrentTranslation[1] = 0.0;
this->CurrentTranslation[2] = 0.0;
this->CurrentAngle = 0.0;
this->CurrentScale[0] = 1.0;
this->CurrentScale[1] = 1.0;
this->CurrentShear[0] = 0.0;
this->CurrentShear[1] = 0.0;
}
//----------------------------------------------------------------------
vtkEllipseRepresent2D::~vtkEllipseRepresent2D()
{
this->Property->Delete();
this->SelectedProperty->Delete();
this->TextProperty->Delete();
this->TextMapper->Delete();
this->TextActor->Delete();
this->HBoxPoints->Delete();
this->HBoxCellArray->Delete();
this->HBox->Delete();
this->HBoxMapper->Delete();
this->HBoxActor->Delete();
this->CirclePoints->Delete();
this->CircleCellArray->Delete();
this->Circle->Delete();
this->CircleMapper->Delete();
this->CircleActor->Delete();
this->HCirclePoints->Delete();
this->HCircleCellArray->Delete();
this->HCircle->Delete();
this->HCircleMapper->Delete();
this->HCircleActor->Delete();
this->XAxis->Delete();
this->YAxis->Delete();
this->HXAxis->Delete();
this->HYAxis->Delete();
this->CurrentTransform->Delete();
this->TotalTransform->Delete();
}
//-------------------------------------------------------------------------
void vtkEllipseRepresent2D::GetTransform(vtkTransform* t)
{
this->CurrentTransform->Identity();
this->CurrentTransform->Translate(this->Origin[0], this->Origin[1], this->Origin[2]);
if (this->InteractionState != vtkAffineRepresentation::MoveOrigin &&
this->InteractionState != vtkAffineRepresentation::MoveOriginX &&
this->InteractionState != vtkAffineRepresentation::MoveOriginY)
{
this->CurrentTransform->Translate(
this->CurrentTranslation[0], this->CurrentTranslation[1], this->CurrentTranslation[2]);
}
this->ApplyShear();
this->CurrentTransform->RotateZ(vtkMath::DegreesFromRadians(this->CurrentAngle));
this->CurrentTransform->Scale(this->CurrentScale[0], this->CurrentScale[1], 1.0);
this->CurrentTransform->Translate(-this->Origin[0], -this->Origin[1], -this->Origin[2]);
t->DeepCopy(this->CurrentTransform);
t->Concatenate(this->TotalTransform);
}
//-------------------------------------------------------------------------
void vtkEllipseRepresent2D::PlaceWidget(double bounds[6])
{
qDebug() << "bounds: " << bounds[0] << "::::" << bounds[1] << "::::" << bounds[2] << "::::" << bounds[3];
this->Origin[0] = (bounds[1] + bounds[0]) / 2.0;
this->Origin[1] = (bounds[3] + bounds[2]) / 2.0;
this->Origin[2] = (bounds[
评论0