grid axis
This commit is contained in:
@@ -31,28 +31,31 @@
|
||||
#define BOOST_TEST_MODULE vtkDetectorChamberTest
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
using namespace uLib;
|
||||
|
||||
BOOST_AUTO_TEST_CASE(vtkDetectorChamberTest) {
|
||||
uLib::DetectorChamber d1, d2;
|
||||
d1.SetSize(uLib::Vector3f(1, 1, 1));
|
||||
d1.SetPosition(uLib::Vector3f(0, 0, 0));
|
||||
d1.Scale(uLib::Vector3f(5, 10, 2));
|
||||
d1.Translate(uLib::Vector3f(0, 0, 0));
|
||||
DetectorChamber d1, d2;
|
||||
d1.SetSize(Vector3f(1, 1, 1));
|
||||
d1.SetPosition(Vector3f(0, 0, 0));
|
||||
d1.Scale(Vector3f(5, 10, 2));
|
||||
d1.Translate(Vector3f(0, 0, 0));
|
||||
|
||||
d2.SetSize(uLib::Vector3f(1, 1, 1));
|
||||
d2.SetPosition(uLib::Vector3f(0, 0, 0));
|
||||
d2.Scale(uLib::Vector3f(5, 10, 2));
|
||||
d2.Translate(uLib::Vector3f(0, 0, 10));
|
||||
d2.SetSize(Vector3f(1, 1, 1));
|
||||
d2.SetPosition(Vector3f(0, 0, 0));
|
||||
d2.Scale(Vector3f(5, 10, 2));
|
||||
d2.Translate(Vector3f(0, 0, 10));
|
||||
|
||||
|
||||
uLib::Vtk::vtkDetectorChamber vtkDetectorChamber(&d1);
|
||||
uLib::Vtk::vtkDetectorChamber vtkDetectorChamber2(&d2);
|
||||
Vtk::vtkDetectorChamber vtkDetectorChamber(&d1);
|
||||
Vtk::vtkDetectorChamber vtkDetectorChamber2(&d2);
|
||||
|
||||
if (!vtkDetectorChamber.GetProp()) {
|
||||
BOOST_FAIL("vtkDetectorChamber::GetProp() returned NULL");
|
||||
}
|
||||
|
||||
if (std::getenv("CTEST_PROJECT_NAME") == nullptr) {
|
||||
uLib::Vtk::Viewer viewer;
|
||||
Vtk::Viewer viewer;
|
||||
viewer.SetGridAxis(Vtk::Viewport::Y);
|
||||
viewer.AddPuppet(vtkDetectorChamber);
|
||||
viewer.AddPuppet(vtkDetectorChamber2);
|
||||
viewer.Start();
|
||||
|
||||
@@ -29,6 +29,7 @@ Viewport::Viewport()
|
||||
, m_Marker(vtkSmartPointer<vtkOrientationMarkerWidget>::New())
|
||||
, m_CameraWidget(nullptr)
|
||||
, m_Colors(vtkSmartPointer<vtkNamedColors>::New())
|
||||
, m_GridAxis(Y)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -267,6 +268,13 @@ bool Viewport::GetGridVisible() const
|
||||
return false;
|
||||
}
|
||||
|
||||
void Viewport::SetGridAxis(Axis axis)
|
||||
{
|
||||
m_GridAxis = axis;
|
||||
UpdateGrid();
|
||||
Render();
|
||||
}
|
||||
|
||||
void Viewport::addProp(vtkProp* prop)
|
||||
{
|
||||
if (m_Renderer) {
|
||||
@@ -313,24 +321,35 @@ void Viewport::UpdateGrid()
|
||||
double focalPoint[3];
|
||||
camera->GetFocalPoint(focalPoint);
|
||||
|
||||
// Align center to spacing
|
||||
double centerX = std::round(focalPoint[0] / spacing) * spacing;
|
||||
double centerY = std::round(focalPoint[1] / spacing) * spacing;
|
||||
// Indices for the two dimensions of the grid plane
|
||||
int idxH, idxV, idxN;
|
||||
if (m_GridAxis == X) { idxH = 1; idxV = 2; idxN = 0; }
|
||||
else if (m_GridAxis == Y) { idxH = 0; idxV = 2; idxN = 1; }
|
||||
else { idxH = 0; idxV = 1; idxN = 2; }
|
||||
|
||||
// Number of lines: enough to cover the screen even if aspect ratio is wide
|
||||
// or if we rotate. 20x20 is usually plenty.
|
||||
// Align center to spacing
|
||||
double centerH = std::round(focalPoint[idxH] / spacing) * spacing;
|
||||
double centerV = std::round(focalPoint[idxV] / spacing) * spacing;
|
||||
double centerN = 0.0; // Grid plane typically passes through the origin
|
||||
|
||||
// Number of lines
|
||||
int numLines = 20;
|
||||
double halfSize = (numLines / 2.0) * spacing;
|
||||
|
||||
double xmin = centerX - halfSize;
|
||||
double xmax = centerX + halfSize;
|
||||
double ymin = centerY - halfSize;
|
||||
double ymax = centerY + halfSize;
|
||||
double minH = centerH - halfSize;
|
||||
double maxH = centerH + halfSize;
|
||||
double minV = centerV - halfSize;
|
||||
double maxV = centerV + halfSize;
|
||||
|
||||
// Update Plane Source
|
||||
m_GridSource->SetOrigin(xmin, ymin, 0.0);
|
||||
m_GridSource->SetPoint1(xmax, ymin, 0.0);
|
||||
m_GridSource->SetPoint2(xmin, ymax, 0.0);
|
||||
// Update Plane Source mapping axes to origin/point1/point2
|
||||
double origin[3] = {0,0,0}, p1[3] = {0,0,0}, p2[3] = {0,0,0};
|
||||
origin[idxH] = minH; origin[idxV] = minV; origin[idxN] = centerN;
|
||||
p1[idxH] = maxH; p1[idxV] = minV; p1[idxN] = centerN;
|
||||
p2[idxH] = minH; p2[idxV] = maxV; p2[idxN] = centerN;
|
||||
|
||||
m_GridSource->SetOrigin(origin);
|
||||
m_GridSource->SetPoint1(p1);
|
||||
m_GridSource->SetPoint2(p2);
|
||||
m_GridSource->SetXResolution(numLines);
|
||||
m_GridSource->SetYResolution(numLines);
|
||||
m_GridSource->Update();
|
||||
|
||||
@@ -65,6 +65,10 @@ public:
|
||||
void SetGridVisible(bool visible);
|
||||
bool GetGridVisible() const;
|
||||
|
||||
enum Axis { X=0, Y, Z };
|
||||
void SetGridAxis(Axis axis);
|
||||
Axis GetGridAxis() const { return m_GridAxis; }
|
||||
|
||||
protected:
|
||||
void SetupPipeline(vtkRenderWindowInteractor* iren);
|
||||
|
||||
@@ -82,6 +86,7 @@ protected:
|
||||
|
||||
vtkSmartPointer<vtkNamedColors> m_Colors;
|
||||
|
||||
Axis m_GridAxis;
|
||||
vtkSmartPointer<vtkHandlerWidget> m_HandlerWidget;
|
||||
std::vector<Puppet*> m_Puppets;
|
||||
vtkSmartPointer<vtkCellPicker> m_Picker;
|
||||
|
||||
Reference in New Issue
Block a user