switch to git no-history version

This commit is contained in:
AndreaRigoni
2018-04-17 15:39:10 +02:00
commit b14311ce09
274 changed files with 27340 additions and 0 deletions

View File

@@ -0,0 +1,13 @@
# TESTS
set( TESTS
vtkViewerTest
vtkContainerBoxTest
vtkMuonScatter
vtkStructuredGridTest
vtkVoxRaytracerTest
vtkVoxImageTest
# vtkTriangleMeshTest
)
include(${VTK_USE_FILE})
uLib_add_tests(${uLib-module})

View File

@@ -0,0 +1,21 @@
include $(top_srcdir)/Common.am
include ../Vtk.am
#AM_DEFAULT_SOURCE_EXT = .cpp
# if HAVE_CHECK
TESTS = \
vtkViewerTest \
vtkContainerBoxTest \
vtkMuonScatter \
vtkStructuredGridTest \
vtkVoxRaytracerTest \
vtkVoxImageTest
# vtkTriangleMeshTest
all: $(TESTS)
LDADD = $(top_srcdir)/libmutom-${PACKAGE_VERSION}.la $(AM_LIBS_ALL)
check_PROGRAMS = $(TESTS)

View File

@@ -0,0 +1,95 @@
/*//////////////////////////////////////////////////////////////////////////////
// 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 >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#include <vtkVersion.h>
#include <vtkSmartPointer.h>
#include <vtkImageData.h>
#include <vtkStructuredPoints.h>
#include <vtkStructuredPointsWriter.h>
#include <vtkPointDataToCellData.h>
#include <vtkCellData.h>
#include <vtkPointData.h>
int main(int, char *[])
{
// Create an image data
vtkSmartPointer<vtkImageData> imageData =
vtkSmartPointer<vtkImageData>::New();
// Specify the size of the image data
imageData->SetDimensions(10,20,15);
#if VTK_MAJOR_VERSION <= 5
imageData->SetNumberOfScalarComponents(1);
imageData->SetScalarTypeToDouble();
#else
imageData->AllocateScalars(VTK_DOUBLE,1);
#endif
int* dims = imageData->GetDimensions();
// int dims[3]; // can't do this
std::cout << "Dims: " << " x: " << dims[0] << " y: " << dims[1] << " z: " << dims[2] << std::endl;
std::cout << "Number of points: " << imageData->GetNumberOfPoints() << std::endl;
std::cout << "Number of cells: " << imageData->GetNumberOfCells() << std::endl;
// Fill every entry of the image data with "2.0"
for (int z = 0; z < dims[2]; z++)
{
for (int y = 0; y < dims[1]; y++)
{
for (int x = 0; x < dims[0]; x++)
{
double* pixel = static_cast<double*>(imageData->GetScalarPointer(x,y,z));
pixel[0] = (double)x+y+z;
}
}
}
// imageData->GetCellData()->SetScalars(imageData->GetPointData()->GetScalars());
vtkSmartPointer<vtkPointDataToCellData> ptoc =
vtkSmartPointer<vtkPointDataToCellData>::New();
ptoc->SetInputConnection(imageData->GetProducerPort());
ptoc->Update();
vtkSmartPointer<vtkStructuredPointsWriter> writer =
vtkSmartPointer<vtkStructuredPointsWriter>::New();
writer->SetInput(ptoc->GetImageDataOutput());
writer->SetFileTypeToASCII();
writer->SetFileName("output.vtk");
writer->Update();
return EXIT_SUCCESS;
}

View File

@@ -0,0 +1,41 @@
/*//////////////////////////////////////////////////////////////////////////////
// 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 >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#include <stdio.h>
#include "Vtk/uLibVtkInterface.h"
#define BEGIN_TESTING(name) \
static int _fail = 0; \
printf("..:: Testing " #name " ::..\n");
#define TEST1(val) _fail += (val)==0
#define TEST0(val) _fail += (val)!=0
#define END_TESTING return _fail;

View File

@@ -0,0 +1,53 @@
/*//////////////////////////////////////////////////////////////////////////////
// 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 >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#include "Vtk/uLibVtkViewer.h"
#include "Math/ContainerBox.h"
#include "Vtk/vtkContainerBox.h"
#include "testing-prototype.h"
using namespace uLib;
int main() {
BEGIN_TESTING(vtk ContainerBox Test);
Vtk::Viewer v_viewer;
ContainerBox box;
box.SetSize(Vector3f(2,3,4));
box.SetPosition(Vector3f(1,2,3));
Vtk::vtkContainerBox v_box(box);
v_viewer.AddPuppet(v_box);
v_viewer.Start();
END_TESTING;
}

View File

@@ -0,0 +1,62 @@
/*//////////////////////////////////////////////////////////////////////////////
// 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 >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#include "Detectors/MuonScatter.h"
#include "Vtk/vtkMuonScatter.h"
#include "Vtk/uLibVtkViewer.h"
#include "testing-prototype.h"
using namespace uLib;
int main()
{
MuonScatter event;
event.LineIn().direction << 0, -1, 1, 0;
event.LineIn().origin << 0, 1, -1, 1;
event.LineOut().direction << 0, -1, 0, 0;
event.LineOut().origin << 0, -1, 0, 1;
Vtk::vtkMuonScatter v_event(event);
v_event.AddPocaPoint(HPoint3f(0,0,0));
v_event.SaveToXMLFile("vtk_testing_muonevent.vtp");
Vtk::Viewer viewer;
// Vtk::Tie<Vtk::vtkMuonScatter> tms;
// tms.DoAction();
// Vtk::Tie<Vtk::Viewer> vms;
// vms.DoAction();
viewer.AddPuppet(v_event);
viewer.Start();
return 0;
}

View File

@@ -0,0 +1,51 @@
/*//////////////////////////////////////////////////////////////////////////////
// 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 >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#include "Math/StructuredGrid.h"
#include "Vtk/vtkStructuredGrid.h"
#include "Vtk/uLibVtkViewer.h"
#include "testing-prototype.h"
using namespace uLib;
int main()
{
StructuredGrid grid(Vector3i(10,10,100));
grid.SetSpacing(Vector3f(3,1,1));
Vtk::vtkStructuredGrid grid_viewer(grid);
Vtk::Viewer viewer;
viewer.AddPuppet(grid_viewer);
viewer.Start();
return 0;
}

View File

@@ -0,0 +1,75 @@
/*//////////////////////////////////////////////////////////////////////////////
// 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 >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#include "Math/TriangleMesh.h"
#include "Vtk/vtkTriangleMesh.h"
#include "testing-prototype.h"
using namespace uLib;
int main()
{
BEGIN_TESTING(Vtk Triangle Mesh);
// { // SIMPLE TESTS //
// TriangleMesh mesh;
// mesh.AddPoint(Vector3f(0,0,0));
// mesh.AddPoint(Vector3f(0,1,0));
// mesh.AddPoint(Vector3f(1,0,0));
// mesh.AddTriangle(Vector3i(0,1,2));
// mesh.PrintSelf(std::cout);
// vtkTriangleMesh v_mesh(mesh);
// v_mesh.Update();
// TestingRenderWidow(&v_mesh);
// }
{ // SIMPLE TESTS //
TriangleMesh mesh;
vtkTriangleMesh v_mesh(mesh);
v_mesh.ReadFromStlFile("prova.stl");
mesh.PrintSelf(std::cout);
TestingRenderWidow(&v_mesh);
}
END_TESTING;
}

View File

@@ -0,0 +1,71 @@
/*//////////////////////////////////////////////////////////////////////////////
// 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 >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <Vtk/uLibVtkViewer.h>
#include <vtkSmartPointer.h>
#include <vtkActor.h>
#include <vtkPolyDataMapper.h>
#include <vtkCubeSource.h>
#include <vtkProperty.h>
#include <vtkRenderer.h>
#include "testing-prototype.h"
using namespace uLib;
int main()
{
BEGIN_TESTING(vtk Viewer Test);
Vtk::Viewer v_viewer;
vtkSmartPointer<vtkCubeSource> cube = vtkSmartPointer<vtkCubeSource>::New();
cube->SetXLength(10);
cube->SetYLength(10);
cube->SetZLength(10);
cube->Update();
vtkSmartPointer<vtkPolyDataMapper> mapper =
vtkSmartPointer<vtkPolyDataMapper>::New();
mapper->SetInputConnection(cube->GetOutputPort());
vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();
actor->SetMapper(mapper);
v_viewer.addProp(actor);
v_viewer.GetRenderer()->Render();
v_viewer.Start();
END_TESTING;
}

View File

@@ -0,0 +1,102 @@
/*//////////////////////////////////////////////////////////////////////////////
// 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 >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#include "Math/VoxImage.h"
#include "Vtk/vtkVoxImage.h"
#include "Vtk/uLibVtkViewer.h"
#include "testing-prototype.h"
using namespace uLib;
struct TestVoxel {
Scalarf Value;
unsigned int Count;
};
int main()
{
BEGIN_TESTING(Vtk Vox Image);
TestVoxel zero = {0,0};
TestVoxel nonzero = {5.5*1E-6,100};
// { // SIMPLE TESTS //
// VoxImage<TestVoxel> img(Vector3i(10,10,10));
// img.SetSpacing(Vector3f(3,3,3));
// img.InitVoxels(zero);
// img[Vector3i(3,3,3)] = nonzero;
// Vtk::vtkVoxImage vtk_img(img);
// vtk_img.SaveToXMLFile("test.vti");
// vtk_img.setShadingPreset(0);
// // vtk_img.ReadFromVKTFile("error.vtk");
// // VoxImage<TestVoxel> img2 = img;
// // Vtk::vtkVoxImage vtk_img2(img2);
// // img2.ExportToVtk("error_saved.vtk",0);
// // vtk_img2.SaveToXMLFile("error_saved.vti");
// Vtk::Viewer viewer;
// viewer.AddPuppet(vtk_img);
// viewer.Start();
// }
{ // SIMPLE TESTS //
VoxImage<TestVoxel> img(Vector3i(10,10,1));
img.SetSpacing(Vector3f(3,3,3));
img.InitVoxels(zero);
img[Vector3i(3,3,0)] = nonzero;
Vtk::vtkVoxImage vtk_img(img);
vtk_img.ReadFromVKTFile("test.vtk");
vtk_img.Update();
// vtk_img.SaveToXMLFile("test.vti");
// vtk_img.setShadingPreset(0);
// Vtk::vtkVoxImage vtk_img2(img2);
// img2.ExportToVtk("error_saved.vtk",0);
// vtk_img2.SaveToXMLFile("error_saved.vti");
Vtk::Viewer viewer;
viewer.AddPuppet(vtk_img);
viewer.Start();
}
END_TESTING;
}

View File

@@ -0,0 +1,156 @@
/*//////////////////////////////////////////////////////////////////////////////
// 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 >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#include <vtkBoxWidget.h>
#include <vtkSmartPointer.h>
#include <vtkCommand.h>
#include <Detectors/MuonScatter.h>
#include <Math/VoxRaytracer.h>
#include "Vtk/vtkMuonScatter.h"
#include "Vtk/vtkStructuredGrid.h"
#include "Vtk/vtkVoxRaytracerRepresentation.h"
#include "Vtk/uLibVtkViewer.h"
// remove
#include <vtkCornerAnnotation.h>
#include "testing-prototype.h"
using namespace uLib;
class vtkWidgetCallback : public vtkCommand
{
public:
static vtkWidgetCallback *New() { return new vtkWidgetCallback; }
void SetTracer(Vtk::vtkVoxRaytracerRepresentation *parent)
{
this->vtk_raytr = parent;
}
void SetMuon (uLib::MuonScatter *muon) { this->muon = muon; }
void SetAnnotation ( vtkCornerAnnotation *annotation) {
this->annotation = annotation;
}
virtual void Execute(vtkObject *caller, unsigned long, void*)
{
char str[40];
vtk_raytr->SetMuon(*muon);
if(annotation)
{
sprintf(str,"total length = %f",vtk_raytr->GetRay().TotalLength());
annotation->SetText(1,str);
for(int i=0; i<vtk_raytr->GetRay().Data().size(); ++i)
{
std::cout << "L[" << i << "] = "
<< vtk_raytr->GetRay().Data().at(i).L << "\n";
}
std::cout << "\n";
}
}
private:
vtkWidgetCallback() :
vtk_raytr(NULL),
muon(NULL),
annotation(NULL) {}
uLib::VoxRaytracer *raytracer;
Vtk::vtkVoxRaytracerRepresentation *vtk_raytr;
uLib::MuonScatter *muon;
vtkCornerAnnotation *annotation;
};
int main()
{
BEGIN_TESTING(vtk VoxRaytracer);
// muon scatter //
MuonScatter muon;
muon.LineIn().origin << -6, 12, -6, 1;
muon.LineIn().direction << 1 , -1 , 1 , 0;
muon.LineOut().origin << 6 , -4 , 6 , 1;
muon.LineOut().direction << 1 , -1 , 1 , 0;
Vtk::vtkMuonScatter v_muon(muon);
// structured grid //
StructuredGrid grid(Vector3i(12,10,12));
grid.SetSpacing(Vector3f(1,1,1));
grid.SetPosition(Vector3f(0,0,0));
Vtk::vtkStructuredGrid v_grid(grid);
// voxraytracer //
VoxRaytracer rt(grid);
HPoint3f pt;
rt.GetEntryPoint(muon.LineIn(),pt);
std::cout << pt.transpose() << "\n";
Vtk::vtkVoxRaytracerRepresentation v_rt(rt);
v_rt.SetMuon(muon);
v_rt.SetRayColor(Vector4f(1,0,0,1));
// // renderer //
Vtk::Viewer viewer;
// widget //
vtkBoxWidget *widget = v_grid.GetWidget();
vtkWidgetCallback *cbk = vtkWidgetCallback::New();
cbk->SetTracer(&v_rt);
cbk->SetMuon(&muon);
cbk->SetAnnotation(viewer.GetAnnotation());
widget->AddObserver(vtkCommand::InteractionEvent, cbk);
widget->SetInteractor(viewer.GetInteractor());
widget->PlaceWidget();
widget->On();
viewer.AddPuppet(v_grid);
viewer.AddPuppet(v_rt);
viewer.AddPuppet(v_muon);
viewer.Start();
END_TESTING;
}