/*////////////////////////////////////////////////////////////////////////////// // CMT Cosmic Muon Tomography project ////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// // // Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova // All rights reserved // // Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > // //////////////////////////////////////////////////////////////////////////////*/ #include #include #include #include #include #include #include #include #include #include #include #include #include "testing-prototype.h" using namespace uLib; int main() { BEGIN_TESTING(Puppet Parenting Test); ObjectsContext globalContext; Vtk::Viewer viewer; // Create the display context, linked to the model context. // It will automatically create visual puppets for each model object. Vtk::vtkObjectsContext viewerContext(&globalContext); viewerContext.ConnectRenderer(viewer.GetRenderer()); // 1. Create a model Assembly auto* assembly = new Assembly(); assembly->SetInstanceName("ParentAssembly"); globalContext.AddObject(assembly); // Verify assembly puppet exists in the viewer context Vtk::Puppet* assemblyPuppet = viewerContext.GetPuppet(assembly); ASSERT_NOT_NULL(assemblyPuppet); // cast to Vtk::Assembly to access child context auto* vtkAss = dynamic_cast(assemblyPuppet); ASSERT_NOT_NULL(vtkAss); // 2. Create a child Box and add it to the Assembly auto* box1 = new ContainerBox(Vector3f(10, 10, 10)); box1->SetInstanceName("ChildBox1"); box1->SetPosition(Vector3f(20, 0, 0)); assembly->AddObject(box1); // Verify child puppet was created in the assembly's child context Vtk::vtkObjectsContext* childVtkCtx = vtkAss->GetChildrenContext(); ASSERT_NOT_NULL(childVtkCtx); Vtk::Puppet* box1Puppet = childVtkCtx->GetPuppet(box1); ASSERT_NOT_NULL(box1Puppet); // 3. Move the parent and verify the child follows assembly->SetPosition(Vector3f(100, 0, 0)); assembly->Updated(); // In VTK assemblies, the child's absolute matrix should reflect the parent's transform vtkProp3D* box1Prop = vtkProp3D::SafeDownCast(box1Puppet->GetProp()); ASSERT_NOT_NULL(box1Prop); vtkMatrix4x4* boxMatrix = box1Prop->GetMatrix(); // Origin (0,0,0) + local(20,0,0) + assembly(100,0,0) = world(120,0,0) ? // Actually, box1->GetPosition() is (20,0,0). // The puppet ApplyTransform sets the prop orientation and position. std::cout << "Checking transformation chain..." << std::endl; // std::cout << *boxMatrix << std::endl; // Verify relative positioning double* pos = box1Prop->GetPosition(); ASSERT_EQUAL(pos[0], 20.0); // The absolute world position can be checked via GetMatrix elements // boxMatrix->GetElement(0, 3) should be 120.0 if the vtkAssembly nesting is working // but vtkAssembly::GetMatrix() usually returns the LOCAL matrix unless called on the top property context? // Actually vtkProp3D::GetMatrix() is the local matrix. // 4. Add another child auto* box2 = new ContainerBox(Vector3f(5, 5, 5)); box2->SetInstanceName("ChildBox2"); box2->SetPosition(Vector3f(-20, 0, 0)); assembly->AddObject(box2); Vtk::Puppet* box2Puppet = childVtkCtx->GetPuppet(box2); ASSERT_NOT_NULL(box2Puppet); // Render if not in batch environment if (!std::getenv("CTEST_PROJECT_NAME")) { viewer.GetRenderer()->ResetCamera(); viewer.Start(); } END_TESTING; }