add detector chamber projection plane representation in vtk
This commit is contained in:
@@ -43,8 +43,8 @@ BOOST_AUTO_TEST_CASE(vtkDetectorChamberTest) {
|
|||||||
|
|
||||||
// d2.SetSize(Vector3f(1, 1, 1));
|
// d2.SetSize(Vector3f(1, 1, 1));
|
||||||
// d2.SetPosition(Vector3f(0, 0, 0));
|
// d2.SetPosition(Vector3f(0, 0, 0));
|
||||||
d2.Scale(Vector3f(1000, 2000, 200));
|
d2.Scale(Vector3f(1_m, 2_m, 20_cm));
|
||||||
d2.Translate(Vector3f(0, 0, 10));
|
d2.Translate(Vector3f(0, 0, 10_m));
|
||||||
|
|
||||||
|
|
||||||
Vtk::vtkDetectorChamber v_d1(&d1);
|
Vtk::vtkDetectorChamber v_d1(&d1);
|
||||||
|
|||||||
@@ -41,20 +41,89 @@
|
|||||||
#include "Vtk/HEP/Detectors/vtkDetectorChamber.h"
|
#include "Vtk/HEP/Detectors/vtkDetectorChamber.h"
|
||||||
#include <vtkBoxWidget.h>
|
#include <vtkBoxWidget.h>
|
||||||
#include <vtkTransformPolyDataFilter.h>
|
#include <vtkTransformPolyDataFilter.h>
|
||||||
|
#include <vtkPlaneSource.h>
|
||||||
|
#include <vtkProperty.h>
|
||||||
|
#include <vtkNew.h>
|
||||||
|
|
||||||
namespace uLib {
|
namespace uLib {
|
||||||
namespace Vtk {
|
namespace Vtk {
|
||||||
|
|
||||||
vtkDetectorChamber::vtkDetectorChamber(DetectorChamber *content)
|
vtkDetectorChamber::vtkDetectorChamber(DetectorChamber *content)
|
||||||
: vtkContainerBox(content) {
|
: vtkContainerBox(content) {
|
||||||
|
m_PlaneSource = vtkPlaneSource::New();
|
||||||
|
|
||||||
|
vtkNew<vtkPolyDataMapper> mapper;
|
||||||
|
mapper->SetInputConnection(m_PlaneSource->GetOutputPort());
|
||||||
|
|
||||||
|
m_PlaneActor = vtkActor::New();
|
||||||
|
m_PlaneActor->SetMapper(mapper);
|
||||||
|
m_PlaneActor->GetProperty()->SetColor(0.2, 0.8, 0.2); // Light green
|
||||||
|
m_PlaneActor->GetProperty()->SetOpacity(0.3);
|
||||||
|
m_PlaneActor->GetProperty()->SetAmbient(1.0);
|
||||||
|
m_PlaneActor->GetProperty()->SetDiffuse(0.0);
|
||||||
|
|
||||||
|
this->SetProp(m_PlaneActor);
|
||||||
|
|
||||||
|
this->contentUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
vtkDetectorChamber::~vtkDetectorChamber() {
|
vtkDetectorChamber::~vtkDetectorChamber() {
|
||||||
|
m_PlaneSource->Delete();
|
||||||
|
m_PlaneActor->Delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
DetectorChamber *vtkDetectorChamber::GetContent() {
|
DetectorChamber *vtkDetectorChamber::GetContent() {
|
||||||
return static_cast<DetectorChamber *>(m_Content);
|
return static_cast<DetectorChamber *>(m_Content);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void vtkDetectorChamber::contentUpdate() {
|
||||||
|
this->BaseClass::contentUpdate();
|
||||||
|
|
||||||
|
if (!m_Content) return;
|
||||||
|
DetectorChamber *c = this->GetContent();
|
||||||
|
Vector3f size = c->GetSize();
|
||||||
|
HLine3f plane = c->GetProjectionPlane();
|
||||||
|
|
||||||
|
// Normalized local space of the chamber
|
||||||
|
float Lx = plane.origin.x() / size.x();
|
||||||
|
float Ly = plane.origin.y() / size.y();
|
||||||
|
float Lz = plane.origin.z() / size.z();
|
||||||
|
|
||||||
|
float Dx = plane.direction.x() * size.x();
|
||||||
|
float Dy = plane.direction.y() * size.y();
|
||||||
|
float Dz = plane.direction.z() * size.z();
|
||||||
|
|
||||||
|
Vector3f normal(Dx, Dy, Dz);
|
||||||
|
normal.normalize();
|
||||||
|
|
||||||
|
// Find spans
|
||||||
|
Vector3f v1;
|
||||||
|
if (std::abs(normal.z()) < 0.9) v1 = Vector3f(0,0,1);
|
||||||
|
else v1 = Vector3f(1,0,0);
|
||||||
|
|
||||||
|
Vector3f p1 = normal.cross(v1).normalized();
|
||||||
|
Vector3f p2 = normal.cross(p1).normalized();
|
||||||
|
|
||||||
|
// Center the visual representation on the box extents (unit box [0,1]^3)
|
||||||
|
// instead of the plane origin (which might be a corner).
|
||||||
|
Vector3f boxCenter(0.5f, 0.5f, 0.5f);
|
||||||
|
Vector3f planePt(Lx, Ly, Lz);
|
||||||
|
Vector3f visualCenter = boxCenter - (boxCenter - planePt).dot(normal) * normal;
|
||||||
|
|
||||||
|
float scale = 1.5; // Slightly larger than the diagonal of a face (1.41)
|
||||||
|
|
||||||
|
m_PlaneSource->SetOrigin(visualCenter.x() - 0.5f*scale*p1.x() - 0.5f*scale*p2.x(),
|
||||||
|
visualCenter.y() - 0.5f*scale*p1.y() - 0.5f*scale*p2.y(),
|
||||||
|
visualCenter.z() - 0.5f*scale*p1.z() - 0.5f*scale*p2.z());
|
||||||
|
|
||||||
|
m_PlaneSource->SetPoint1(visualCenter.x() + 0.5f*scale*p1.x() - 0.5f*scale*p2.x(),
|
||||||
|
visualCenter.y() + 0.5f*scale*p1.y() - 0.5f*scale*p2.y(),
|
||||||
|
visualCenter.z() + 0.5f*scale*p1.z() - 0.5f*scale*p2.z());
|
||||||
|
|
||||||
|
m_PlaneSource->SetPoint2(visualCenter.x() - 0.5f*scale*p1.x() + 0.5f*scale*p2.x(),
|
||||||
|
visualCenter.y() - 0.5f*scale*p1.y() + 0.5f*scale*p2.y(),
|
||||||
|
visualCenter.z() - 0.5f*scale*p1.z() + 0.5f*scale*p2.z());
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace Vtk
|
} // namespace Vtk
|
||||||
} // namespace uLib
|
} // namespace uLib
|
||||||
@@ -39,6 +39,8 @@
|
|||||||
#include <vtkBoxWidget.h>
|
#include <vtkBoxWidget.h>
|
||||||
#include <vtkTransformPolyDataFilter.h>
|
#include <vtkTransformPolyDataFilter.h>
|
||||||
|
|
||||||
|
class vtkPlaneSource;
|
||||||
|
|
||||||
namespace uLib {
|
namespace uLib {
|
||||||
namespace Vtk {
|
namespace Vtk {
|
||||||
|
|
||||||
@@ -53,6 +55,12 @@ public:
|
|||||||
virtual ~vtkDetectorChamber();
|
virtual ~vtkDetectorChamber();
|
||||||
|
|
||||||
Content *GetContent();
|
Content *GetContent();
|
||||||
|
|
||||||
|
virtual void contentUpdate() override;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
vtkActor *m_PlaneActor;
|
||||||
|
vtkPlaneSource *m_PlaneSource;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Vtk
|
} // namespace Vtk
|
||||||
|
|||||||
Reference in New Issue
Block a user