Skip to content

Commit

Permalink
Make it compile with v22.06 (and wo compat) (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
fredroy authored Jul 5, 2022
1 parent 4f87552 commit 26b6bb8
Show file tree
Hide file tree
Showing 11 changed files with 103 additions and 108 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-20.04, macos-10.15, windows-2019]
sofa_branch: [master, v21.12]
sofa_branch: [master, v22.06]

steps:
- name: Setup SOFA and environment
id: sofa
uses: sofa-framework/sofa-setup-action@v3.0
uses: sofa-framework/sofa-setup-action@v4
with:
sofa_root: ${{ github.workspace }}/sofa
sofa_version: ${{ matrix.sofa_branch }}
Expand Down
19 changes: 11 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
cmake_minimum_required(VERSION 3.12)
project(Registration VERSION 0.1)

find_package(Sofa.GL REQUIRED)
sofa_find_package(SofaMiscCollision REQUIRED)
sofa_find_package(SofaOpenglVisual REQUIRED)
sofa_find_package(SofaExporter REQUIRED)
find_package(Sofa.Helper REQUIRED)
sofa_find_package(Sofa.GL REQUIRED)
sofa_find_package(Sofa.Component.IO.Mesh REQUIRED)
sofa_find_package(Sofa.Component.Engine.Generate REQUIRED)
sofa_find_package(Sofa.Component.Collision.Response.Mapper REQUIRED)
sofa_find_package(SofaDistanceGrid QUIET)
sofa_find_package(image QUIET)
find_package(Eigen3 REQUIRED)

set(REGISTRATION_SRC "src/${PROJECT_NAME}")

Expand Down Expand Up @@ -54,11 +54,14 @@ else()
endif()

# Config files and install rules for pythons scripts
sofa_set_python_directory(Registration "python")
sofa_install_pythonscripts(
PLUGIN_NAME ${PROJECT_NAME}
PYTHONSCRIPTS_SOURCE_DIR "python"
)

add_library(${PROJECT_NAME} SHARED ${HEADER_FILES} ${SOURCE_FILES} ${README_FILES} ${PYTHON_FILES})
target_link_libraries(${PROJECT_NAME} PUBLIC SofaMeshCollision SofaMiscCollision SofaBaseCollision SofaBaseVisual SofaExporter SofaOpenglVisual SofaLoader SofaMiscForceField SofaGeneralEngine)
target_link_libraries(${PROJECT_NAME} PUBLIC Eigen3::Eigen)
target_link_libraries(${PROJECT_NAME} PUBLIC Sofa.Component.IO.Mesh Sofa.Component.Collision.Response.Mapper Sofa.Component.Engine.Generate)
target_link_libraries(${PROJECT_NAME} PUBLIC Sofa.GL)

if(image_FOUND)
target_link_libraries(${PROJECT_NAME} PUBLIC image)
Expand Down
23 changes: 4 additions & 19 deletions RegistrationConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,20 @@

@PACKAGE_INIT@

set(REGISTRATION_HAVE_SOFAMISCCOLLISION @REGISTRATION_HAVE_SOFAMISCCOLLISION@)
set(REGISTRATION_HAVE_SOFAOPENGLVISUAL @REGISTRATION_HAVE_SOFAOPENGLVISUAL@)
set(REGISTRATION_HAVE_SOFAEXPORTER @REGISTRATION_HAVE_SOFAEXPORTER@)
set(REGISTRATION_HAVE_SOFADISTANCEGRID @REGISTRATION_HAVE_SOFADISTANCEGRID@)
set(REGISTRATION_HAVE_IMAGE @REGISTRATION_HAVE_IMAGE@)
set(REGISTRATION_HAVE_SOFA_GL @REGISTRATION_HAVE_SOFA_GL@)

find_package(SofaGui REQUIRED)
find_package(image QUIET)
find_package(Eigen3 REQUIRED)
find_package(Sofa.GL QUIET REQUIRED)
find_package(Sofa.Component.IO.Mesh QUIET REQUIRED)
find_package(Sofa.Component.Engine.Generate QUIET REQUIRED)
find_package(Sofa.Component.Collision.Response.Mapper QUIET REQUIRED)

if(REGISTRATION_HAVE_SOFAMISCCOLLISION)
find_package(SofaMiscCollision QUIET REQUIRED)
endif()
if(REGISTRATION_HAVE_SOFAOPENGLVISUAL)
find_package(SofaOpenglVisual QUIET REQUIRED)
endif()
if(REGISTRATION_HAVE_SOFAEXPORTER)
find_package(SofaExporter QUIET REQUIRED)
endif()
if(REGISTRATION_HAVE_SOFADISTANCEGRID)
find_package(SofaDistanceGrid QUIET REQUIRED)
endif()
if(REGISTRATION_HAVE_IMAGE)
find_package(Image QUIET REQUIRED)
endif()
if(REGISTRATION_HAVE_SOFA_GL)
find_package(Sofa.GL REQUIRED)
endif()

if(NOT TARGET Registration)
include("${CMAKE_CURRENT_LIST_DIR}/RegistrationTargets.cmake")
Expand Down
26 changes: 11 additions & 15 deletions src/Registration/ClosestPointRegistrationForceField.inl
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,13 @@
#include <omp.h>
#endif

#include <SofaLoader/MeshOBJLoader.h>
#include <SofaGeneralEngine/NormalsFromPoints.h>
#include <sofa/component/io/mesh/MeshOBJLoader.h>
#include <sofa/component/engine/generate/NormalsFromPoints.h>
#include <limits>
#include <set>
#include <iterator>
#include <sofa/gl/Color.h>

using std::cerr;
using std::endl;



namespace sofa
{
Expand Down Expand Up @@ -106,22 +102,22 @@ void ClosestPointRegistrationForceField<DataTypes>::init()

// Get source triangles
if(!sourceTriangles.getValue().size()) {
sofa::component::loader::MeshOBJLoader *meshobjLoader;
this->getContext()->get( meshobjLoader, core::objectmodel::BaseContext::Local);
if (meshobjLoader)
sofa::component::io::mesh::MeshOBJLoader *MeshOBJLoader;
this->getContext()->get( MeshOBJLoader, core::objectmodel::BaseContext::Local);
if (MeshOBJLoader)
{
if(sourceTriangles.setParent(&meshobjLoader->d_triangles))
if(sourceTriangles.setParent(&MeshOBJLoader->d_triangles))
{
msg_info()<<"imported triangles from "<<meshobjLoader->getName();
msg_info()<<"imported triangles from "<<MeshOBJLoader->getName();
}
else
{
msg_warning()<<"unable to import triangles from "<<meshobjLoader->getName();
msg_warning()<<"unable to import triangles from "<<MeshOBJLoader->getName();
}
}
}
// Get source normals
if(!sourceNormals.getValue().size()) serr<<"normals of the source model not found"<<sendl;
if(!sourceNormals.getValue().size()) msg_error()<<"normals of the source model not found";
}

template<class DataTypes>
Expand Down Expand Up @@ -328,7 +324,7 @@ void ClosestPointRegistrationForceField<DataTypes>::addForce(const core::Mechani
// add rest spring force
for (unsigned int i=0; i<nb; i++)
{
//serr<<"addForce() between "<<i<<" and "<<closestPos[i]<<sendl;
//msg_error()<<"addForce() between "<<i<<" and "<<closestPos[i];
Coord u = this->closestPos[i]-x[i];
Real nrm2 = u.norm2();
Real k = this->ks.getValue();
Expand Down Expand Up @@ -405,7 +401,7 @@ void ClosestPointRegistrationForceField<DataTypes>::draw(const core::visual::Vis
if (showArrowSize.getValue()==0 || drawMode.getValue() == 0) vparams->drawTool()->drawLines(points, 1, c);
else if (drawMode.getValue() == 1) for (unsigned int i=0;i<points.size()/2;++i) vparams->drawTool()->drawCylinder(points[2*i+1], points[2*i], showArrowSize.getValue(), c);
else if (drawMode.getValue() == 2) for (unsigned int i=0;i<points.size()/2;++i) vparams->drawTool()->drawArrow(points[2*i+1], points[2*i], showArrowSize.getValue(), c);
else serr << "No proper drawing mode found!" << sendl;
else msg_error() << "No proper drawing mode found!";
}

if(drawColorMap.getValue())
Expand Down
7 changes: 6 additions & 1 deletion src/Registration/GroupwiseRegistrationEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,12 @@ class GroupwiseRegistrationEngine : public core::DataEngine
{
helper::ReadAccessor<Data<VecCoord> > pos(vf_inputs[i]);
helper::WriteOnlyAccessor<Data<VecCoord> > outPos(vf_outputs[i]);
if(N!=pos.size()) { serr<<"input"<<i+1<<" has an invalid size"<<sendl; return; }

if(N!=pos.size())
{
msg_error() << "input" << i + 1 << " has an invalid size" ;
return;
}

affine R; Coord t;
ClosestRigid(pos.ref(), pos0.ref(), R, t);
Expand Down
63 changes: 32 additions & 31 deletions src/Registration/InertiaAlign.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ void InertiaAlign::init()

}
}
sout << "Source intertia matrix"<<sendl<<eigenSourceInertiaMatrix << sendl;
sout << "Target intertia matrix"<<sendl<<eigenTargetInertiaMatrix << sendl;
msg_info() << "Source intertia matrix \n" << eigenSourceInertiaMatrix;
msg_info() << "Target intertia matrix \n" << eigenTargetInertiaMatrix;

Eigen::EigenSolver<Eigen::Matrix3d> solverTarget(eigenTargetInertiaMatrix);
Eigen::EigenSolver<Eigen::Matrix3d> solverSource(eigenSourceInertiaMatrix);
Expand Down Expand Up @@ -244,24 +244,25 @@ void InertiaAlign::init()
Lzt = sqrt(abs( Txx+Tyy-Tzz)/2);


sout << "EigenVectorsSource =" << sendl;
msg_info() << "EigenVectorsSource =";
for(unsigned int i=0;i<3;i++)
{
for(unsigned int j=0;j<3;j++)
sout << eigenvectorsSource(i,j) << " ";
sout << sendl;
msg_info() << eigenvectorsSource(i,j) << " ";

msg_info() << "\n";

}

SReal scale_u = Lxs / Lxt;
SReal scale_v = Lys / Lyt;
SReal scale_w = Lzs / Lzt;

sout << "Scale X = " << scale_u << "Scale Y = "<< scale_v << "Scale Z = " << scale_w << sendl;
msg_info() << "Scale X = " << scale_u << "Scale Y = "<< scale_v << "Scale Z = " << scale_w;


sout << "Lxs = " <<Lxs<< "Lys = " <<Lys<< "Lzs = " <<Lzs << sendl;
sout << "Lxt = " <<Lxt<< "Lyt = " <<Lyt<< "Lzt = " <<Lzt << sendl;
msg_info() << "Lxs = " <<Lxs<< "Lys = " <<Lys<< "Lzs = " <<Lzs;
msg_info() << "Lxt = " <<Lxt<< "Lyt = " <<Lyt<< "Lzt = " <<Lzt;
/*Creation of the two 4x4 transformation matrix:
*
*MTransformSource :
Expand Down Expand Up @@ -325,7 +326,7 @@ void InertiaAlign::init()
}


sout <<"Source Directe? "<< sdirect << sendl;
msg_info() <<"Source Directe? "<< sdirect;

for(unsigned int i=0;i<3;i++)
{
Expand All @@ -348,7 +349,7 @@ void InertiaAlign::init()
}
}

sout <<"Target Directe? "<< sdirect << sendl;
msg_info() <<"Target Directe? "<< sdirect;

//Normalised last line
MTransformTarget(3,3) = 1;
Expand Down Expand Up @@ -393,25 +394,25 @@ void InertiaAlign::init()

}

sout << "MTransformSource before inversion ="<< sendl;
msg_info() << "MTransformSource before inversion =";
for(unsigned int i=0;i<4;i++)
{
for(unsigned int j=0;j<4;j++)
{
sout <<MTransformSource(i,j)<< " ";
msg_info() <<MTransformSource(i,j)<< " ";
}
sout << sendl;
msg_info() << "\n";
}

MTransformSource = inverseTransform(MTransformSource);
sout << "MTransformSource after inversion ="<< sendl;
msg_info() << "MTransformSource after inversion =";
for(unsigned int i=0;i<4;i++)
{
for(unsigned int j=0;j<4;j++)
{
sout <<MTransformSource(i,j)<< " ";
msg_info() <<MTransformSource(i,j)<< " ";
}
sout << sendl;
msg_info() << "\n";
}
type::Matrix4 MTranslation;
for(unsigned int i=0;i<4;i++)
Expand Down Expand Up @@ -503,7 +504,7 @@ void InertiaAlign::init()
}
(*m_positions.beginEdit()) = positionDistSource;
}
sout << "Indice choisi : " << indice_min << " avec une distance de " << distance_min << sendl;
msg_info() << "Indice choisi : " << indice_min << " avec une distance de " << distance_min;
//Compute the best transformation
switch(indice_min)
{
Expand Down Expand Up @@ -548,9 +549,9 @@ void InertiaAlign::init()
{
for(unsigned int j=0;j<4;j++)
{
sout << MTransformTarget(k,j) << " ";
msg_info() << MTransformTarget(k,j) << " ";
}
sout << sendl;
msg_info();
}
MTransformSource = MTransformTarget * MTransformSource;

Expand All @@ -559,9 +560,9 @@ void InertiaAlign::init()
{
for(unsigned int j=0;j<4;j++)
{
sout << MTransformSource(k,j) << " ";
msg_info() << MTransformSource(k,j) << " ";
}
sout << sendl;
msg_info();
}

Eigen::Matrix4d MDeterminantTest;
Expand All @@ -573,7 +574,7 @@ void InertiaAlign::init()
}
}
if(MDeterminantTest.determinant()<0)
sout << "The MTransformSourceMatrix is not a Transformation matrix" << sendl;
msg_info() << "The MTransformSourceMatrix is not a Transformation matrix";
for (size_t i = 0; i < waPositions.size(); i++)
{
type::Vector4 pointS,pointT;
Expand Down Expand Up @@ -648,14 +649,14 @@ Matrix4 InertiaAlign::inverseTransform(Matrix4 transformToInvert)
Vector3 Translation;
Matrix4 transformInverted;

sout << "Before inversion"<< sendl;
msg_info() << "Before inversion";
for(unsigned int i=0;i<4;i++)
{
for(unsigned int j=0;j<4;j++)
{
sout << transformToInvert(i,j)<< " ";
msg_info() << transformToInvert(i,j)<< " ";
}
sout << sendl;
msg_info() << "\n";
}
for(unsigned int i=0;i<3;i++)
{
Expand All @@ -668,16 +669,16 @@ Matrix4 InertiaAlign::inverseTransform(Matrix4 transformToInvert)

bool bS = type::invertMatrix(rotationInverted,rotationToInvert);

sout << "Translation = " << Translation;
msg_info() << "Translation = " << Translation;
if(!bS)
{
sout <<"Error : Source transformation matrix is not invertible"<<sendl;
msg_info() <<"Error : Source transformation matrix is not invertible";
}
else //Compute R-1 * t
{
Translation = (-1*rotationInverted * Translation);
}
sout << "Translation = " << Translation;
msg_info() << "Translation = " << Translation;
for(unsigned int i=0;i<3;i++)
{
for(unsigned int j=0;j<3;j++)
Expand All @@ -688,14 +689,14 @@ Matrix4 InertiaAlign::inverseTransform(Matrix4 transformToInvert)
}
transformInverted(3,3)=1;

sout << "After inversion"<< sendl;
msg_info() << "After inversion";
for(unsigned int i=0;i<4;i++)
{
for(unsigned int j=0;j<4;j++)
{
sout << transformInverted(i,j)<< " ";
msg_info() << transformInverted(i,j)<< " ";
}
sout << sendl;
msg_info() << "\n";
}
return transformInverted;

Expand Down
Loading

0 comments on commit 26b6bb8

Please sign in to comment.