refactor: update Geant scene visualization to use PhysicalVolumes instead of raw Solids for improved placement and context handling.
This commit is contained in:
@@ -25,53 +25,59 @@ using namespace uLib;
|
||||
int main(int argc, char** argv) {
|
||||
bool interactive = (argc > 1 && std::string(argv[1]) == "-i");
|
||||
|
||||
// 1. Create a BoxSolid
|
||||
ContainerBox box;
|
||||
box.Scale(Vector3f(1_m, 2_m, 3_m));
|
||||
Geant::BoxSolid gBox("MyBox", &box);
|
||||
gBox.Update();
|
||||
|
||||
Vtk::BoxSolid vtkBox(&gBox);
|
||||
|
||||
// 2. Create a TessellatedSolid
|
||||
Geant::TessellatedSolid gTess("MyTess");
|
||||
TriangleMesh mesh;
|
||||
// Create a simple pyramid
|
||||
mesh.Points().push_back(Vector3f(0, 0, 1_m)); // apex
|
||||
mesh.Points().push_back(Vector3f(-1_m, -1_m, 0));
|
||||
mesh.Points().push_back(Vector3f( 1_m, -1_m, 0));
|
||||
mesh.Points().push_back(Vector3f( 1_m, 1_m, 0));
|
||||
mesh.Points().push_back(Vector3f(-1_m, 1_m, 0));
|
||||
|
||||
mesh.Triangles().push_back(Vector3i(1, 2, 0));
|
||||
mesh.Triangles().push_back(Vector3i(2, 3, 0));
|
||||
mesh.Triangles().push_back(Vector3i(3, 4, 0));
|
||||
mesh.Triangles().push_back(Vector3i(4, 1, 0));
|
||||
mesh.Triangles().push_back(Vector3i(1, 3, 2)); // base
|
||||
mesh.Triangles().push_back(Vector3i(1, 4, 3)); // base
|
||||
|
||||
gTess.SetMesh(mesh);
|
||||
gTess.Update();
|
||||
|
||||
Vtk::TessellatedSolid vtkTess(&gTess);
|
||||
|
||||
// 3. Visualization setup
|
||||
Vtk::Viewer viewer;
|
||||
|
||||
// 1. Create a BoxSolid
|
||||
SmartPointer<ContainerBox> box(new ContainerBox());
|
||||
box->Scale(Vector3f(1_m, 2_m, 3_m));
|
||||
SmartPointer<Geant::BoxSolid> gBox(new Geant::BoxSolid("MyBox", box));
|
||||
gBox->Update();
|
||||
|
||||
SmartPointer<Geant::LogicalVolume> lvBox(new Geant::LogicalVolume("BoxLV"));
|
||||
lvBox->SetSolid(gBox);
|
||||
SmartPointer<Geant::PhysicalVolume> pvBox(new Geant::PhysicalVolume("BoxPV", lvBox));
|
||||
Vtk::BoxSolid vtkBox(pvBox);
|
||||
vtkBox.AddToViewer(viewer);
|
||||
|
||||
// 2. Create a TessellatedSolid
|
||||
SmartPointer<Geant::TessellatedSolid> gTess(new Geant::TessellatedSolid("MyTess"));
|
||||
SmartPointer<TriangleMesh> mesh(new TriangleMesh());
|
||||
// ... same points ...
|
||||
mesh->Points().push_back(Vector3f(0, 0, 1_m)); // apex
|
||||
mesh->Points().push_back(Vector3f(-1_m, -1_m, 0));
|
||||
mesh->Points().push_back(Vector3f( 1_m, -1_m, 0));
|
||||
mesh->Points().push_back(Vector3f( 1_m, 1_m, 0));
|
||||
mesh->Points().push_back(Vector3f(-1_m, 1_m, 0));
|
||||
|
||||
mesh->Triangles().push_back(Vector3i(1, 2, 0));
|
||||
mesh->Triangles().push_back(Vector3i(2, 3, 0));
|
||||
mesh->Triangles().push_back(Vector3i(3, 4, 0));
|
||||
mesh->Triangles().push_back(Vector3i(4, 1, 0));
|
||||
mesh->Triangles().push_back(Vector3i(1, 3, 2)); // base
|
||||
mesh->Triangles().push_back(Vector3i(1, 4, 3)); // base
|
||||
|
||||
gTess->SetMesh(mesh.Get());
|
||||
gTess->Update();
|
||||
|
||||
SmartPointer<Geant::LogicalVolume> lvTess(new Geant::LogicalVolume("TessLV"));
|
||||
lvTess->SetSolid(gTess);
|
||||
SmartPointer<Geant::PhysicalVolume> pvTess(new Geant::PhysicalVolume("TessPV", lvTess));
|
||||
Vtk::TessellatedSolid vtkTess(pvTess);
|
||||
vtkTess.AddToViewer(viewer);
|
||||
|
||||
// Color them differently
|
||||
vtkBox.SetColor(0.8, 0.2, 0.2); // Redish box
|
||||
vtkTess.SetColor(0.2, 0.8, 0.2); // Greenish tess
|
||||
|
||||
// Position tessellated solid away from box
|
||||
// Position tessellated solid away from box using the PhysicalVolume
|
||||
Matrix4f trans = Matrix4f::Identity();
|
||||
trans.block<3,1>(0,3) = Vector3f(5_m, 0, 0);
|
||||
gTess.SetTransform(trans);
|
||||
pvTess->SetMatrix(trans);
|
||||
vtkTess.Update();
|
||||
|
||||
std::cout << "..:: Testing vtkSolidsTest ::.." << std::endl;
|
||||
std::cout << "Box and Tessellated solids initialized." << std::endl;
|
||||
std::cout << "Box and Tessellated solids (placed via PhysicalVolumes) initialized." << std::endl;
|
||||
|
||||
if (interactive) {
|
||||
viewer.ZoomAuto();
|
||||
|
||||
Reference in New Issue
Block a user