Skip to content

Commit 2b03750

Browse files
authored
Move adaptivity code to a new plugin Shell.Adaptivity (#14)
* Create new plugin to move code related to adaptivity * move files related to adaptivity * fix partially compilation * fix compilation partially * fix PointData and TriangleData * comment code because it does not compile
1 parent 477df1a commit 2b03750

22 files changed

Lines changed: 320 additions & 261 deletions

CMakeLists.txt

Lines changed: 2 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ sofa_find_package(Sofa.GL REQUIRED)
1111

1212
set(README_FILE README.md)
1313

14-
option(SOFA-PLUGIN_SHELLS_ADAPTIVITY "Enables shells adaptivity" OFF)
15-
1614
# List all files
1715
set(SHELL_SRC_DIR src/Shell)
1816
set(HEADER_FILES
@@ -70,40 +68,6 @@ set(SOURCE_FILES
7068
${SHELL_SRC_DIR}/shells2/mapping/BezierShellMechanicalMapping.cpp
7169
)
7270

73-
if(SOFA-PLUGIN_SHELLS_ADAPTIVITY)
74-
set(COMPILER_DEFINE "SOFA_BUILD_SHELLS_ADAPTIVITY")
75-
76-
list(APPEND HEADER_FILES
77-
${SHELL_SRC_DIR}/controller/AdaptiveCuttingController.h
78-
${SHELL_SRC_DIR}/controller/AdaptiveCuttingController.inl
79-
${SHELL_SRC_DIR}/controller/Test2DAdapter.h
80-
${SHELL_SRC_DIR}/controller/Test2DAdapter.inl
81-
${SHELL_SRC_DIR}/misc/Optimize2DSurface.h
82-
${SHELL_SRC_DIR}/misc/Optimize2DSurface.inl
83-
${SHELL_SRC_DIR}/misc/SurfaceParametrization.h
84-
${SHELL_SRC_DIR}/misc/SurfaceParametrization.inl
85-
)
86-
87-
list(APPEND SOURCE_FILES
88-
${SHELL_SRC_DIR}/controller/AdaptiveCuttingController.cpp
89-
${SHELL_SRC_DIR}/controller/Test2DAdapter.cpp
90-
${SHELL_SRC_DIR}/misc/Optimize2DSurface.cpp
91-
${SHELL_SRC_DIR}/misc/SurfaceParametrization.cpp
92-
)
93-
94-
if(SofaGui_FOUND AND SofaOpenglVisual_FOUND)
95-
list(APPEND HEADER_FILES
96-
${SHELL_SRC_DIR}/cutting/AdaptiveCutting.h
97-
)
98-
99-
list(APPEND SOURCE_FILES
100-
${SHELL_SRC_DIR}/cutting/AdaptiveCutting.cpp
101-
)
102-
endif()
103-
104-
endif()
105-
106-
10771
# Create the plugin library
10872
add_library(${PROJECT_NAME} SHARED ${HEADER_FILES} ${SOURCE_FILES} ${README_FILES})
10973

@@ -124,3 +88,5 @@ sofa_create_package_with_targets(
12488
INCLUDE_INSTALL_DIR ${PROJECT_NAME}
12589
RELOCATABLE "plugins"
12690
)
91+
92+
sofa_add_subdirectory(plugin extensions/Shell.Adaptivity Shell.Adaptivity)
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# CMakeLists.txt for Shell.Adaptivity plugin
2+
cmake_minimum_required(VERSION 3.12)
3+
project(Shell.Adaptivity VERSION 1.0 LANGUAGES CXX)
4+
5+
find_package(Sofa.Config REQUIRED)
6+
sofa_find_package(Shell REQUIRED)
7+
sofa_find_package(Sofa.GUI.Component REQUIRED)
8+
sofa_find_package(Sofa.GUI.Common REQUIRED)
9+
10+
set(HEADER_FILES
11+
src/Shell/Adaptivity/config.h.in
12+
src/Shell/Adaptivity/init.h
13+
14+
src/Shell/Adaptivity/controller/AdaptiveCuttingController.h
15+
src/Shell/Adaptivity/controller/AdaptiveCuttingController.inl
16+
src/Shell/Adaptivity/controller/Test2DAdapter.h
17+
src/Shell/Adaptivity/controller/Test2DAdapter.inl
18+
19+
src/Shell/Adaptivity/cutting/AdaptiveCutting.h
20+
21+
src/Shell/Adaptivity/misc/Optimize2DSurface.h
22+
src/Shell/Adaptivity/misc/Optimize2DSurface.inl
23+
src/Shell/Adaptivity/misc/SurfaceParametrization.h
24+
src/Shell/Adaptivity/misc/SurfaceParametrization.inl
25+
)
26+
27+
set(SOURCE_FILES
28+
src/Shell/Adaptivity/init.cpp
29+
30+
src/Shell/Adaptivity/controller/AdaptiveCuttingController.cpp
31+
src/Shell/Adaptivity/controller/Test2DAdapter.cpp
32+
33+
src/Shell/Adaptivity/cutting/AdaptiveCutting.cpp
34+
35+
src/Shell/Adaptivity/misc/Optimize2DSurface.cpp
36+
src/Shell/Adaptivity/misc/SurfaceParametrization.cpp
37+
)
38+
39+
add_library(${PROJECT_NAME} SHARED ${HEADER_FILES} ${SOURCE_FILES})
40+
target_link_libraries(${PROJECT_NAME} PUBLIC Shell Sofa.GUI.Component Sofa.GUI.Common)
41+
42+
sofa_create_package_with_targets(
43+
PACKAGE_NAME ${PROJECT_NAME}
44+
PACKAGE_VERSION ${PROJECT_VERSION}
45+
TARGETS ${PROJECT_NAME} AUTO_SET_TARGET_PROPERTIES
46+
INCLUDE_SOURCE_DIR "src"
47+
INCLUDE_INSTALL_DIR ${PROJECT_NAME}
48+
RELOCATABLE "plugins"
49+
)
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# CMake package configuration file for the plugin @PROJECT_NAME@
2+
3+
@PACKAGE_GUARD@
4+
@PACKAGE_INIT@
5+
6+
find_package(Shell QUIET REQUIRED)
7+
8+
if(NOT TARGET @PROJECT_NAME@)
9+
include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@Targets.cmake")
10+
endif()
11+
12+
check_required_components(Shell.Adaptivity)
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#pragma once
2+
#include <sofa/config.h>
3+
4+
#ifdef SOFA_BUILD_SHELL_ADAPTIVITY
5+
# define SOFA_TARGET @PROJECT_NAME@
6+
# define SHELL_ADAPTIVITY_API SOFA_EXPORT_DYNAMIC_LIBRARY
7+
#else
8+
# define SHELL_ADAPTIVITY_API SOFA_IMPORT_DYNAMIC_LIBRARY
9+
#endif
10+
11+
namespace shelladaptivity
12+
{
13+
constexpr const char* MODULE_NAME = "@PROJECT_NAME@";
14+
constexpr const char* MODULE_VERSION = "@PROJECT_VERSION@";
15+
}

src/Shell/controller/AdaptiveCuttingController.cpp renamed to extensions/Shell.Adaptivity/src/Shell/Adaptivity/controller/AdaptiveCuttingController.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#include <SofaShells/config.h>
2-
#include <SofaShells/cutting/AdaptiveCuttingController.inl>
1+
#include <Shell/Adaptivity/config.h>
2+
#include <Shell/Adaptivity/controller/AdaptiveCuttingController.inl>
33
#include <sofa/core/ObjectFactory.h>
44

55

@@ -20,20 +20,20 @@ SOFA_DECL_CLASS(AdaptiveCuttingController)
2020
int AdaptiveCuttingControllerClass = core::RegisterObject(
2121
"Controller that handles the cutting method based on mesh adaptivity.")
2222
#ifdef SOFA_FLOAT
23-
.add< AdaptiveCuttingController<type::Vec3fTypes> >(true) // default template
23+
.add< AdaptiveCuttingController<defaulttype::Vec3fTypes> >(true) // default template
2424
#else
25-
.add< AdaptiveCuttingController<type::Vec3dTypes> >(true) // default template
25+
.add< AdaptiveCuttingController<defaulttype::Vec3dTypes> >(true) // default template
2626
# ifndef SOFA_DOUBLE
27-
.add< AdaptiveCuttingController<type::Vec3fTypes> >()
27+
.add< AdaptiveCuttingController<defaulttype::Vec3fTypes> >()
2828
# endif
2929
#endif
3030
;
3131

3232
#ifndef SOFA_FLOAT
33-
template class SOFA_SHELLS_API AdaptiveCuttingController<type::Vec3dTypes>;
33+
template class SHELL_ADAPTIVITY_API AdaptiveCuttingController<defaulttype::Vec3dTypes>;
3434
#endif //SOFA_FLOAT
3535
#ifndef SOFA_DOUBLE
36-
template class SOFA_SHELLS_API AdaptiveCuttingController<type::Vec3fTypes>;
36+
template class SHELL_ADAPTIVITY_API AdaptiveCuttingController<defaulttype::Vec3fTypes>;
3737
#endif //SOFA_DOUBLE
3838

3939
} // namespace controller

src/Shell/controller/AdaptiveCuttingController.h renamed to extensions/Shell.Adaptivity/src/Shell/Adaptivity/controller/AdaptiveCuttingController.h

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#ifndef SOFA_COMPONENT_CONTROLLER_ADAPTIVECUTTINGCONTROLLER_H
22
#define SOFA_COMPONENT_CONTROLLER_ADAPTIVECUTTINGCONTROLLER_H
33

4-
#include <SofaUserInteraction/Controller.h>
4+
#include <sofa/component/controller/Controller.h>
55

66
#include <sofa/defaulttype/VecTypes.h>
77
#include <sofa/type/Vec.h>
@@ -11,14 +11,13 @@
1111
#include <sofa/gui/component/performer/MouseInteractor.h>
1212
#include <sofa/component/topology/container/dynamic/TriangleSetTopologyContainer.h>
1313
#include <sofa/component/topology/container/dynamic/TriangleSetTopologyModifier.h>
14-
#include <sofa/component/topology/container/dynamic/TriangleSetTopologyAlgorithms.h>
1514
#include <sofa/component/topology/container/dynamic/TriangleSetGeometryAlgorithms.h>
1615
#include <sofa/core/topology/TopologyData.h>
1716

1817
#include <sofa/helper/map.h>
1918
#include <sofa/type/vector.h>
2019

21-
#include <SofaShells/controller/Test2DAdapter.h>
20+
#include <Shell/Adaptivity/controller/Test2DAdapter.h>
2221

2322
namespace sofa
2423
{
@@ -33,7 +32,7 @@ namespace controller
3332
class CuttingAdapter
3433
{
3534
public:
36-
virtual void setTrackedPoint(const collision::BodyPicked &picked) = 0;
35+
virtual void setTrackedPoint(const sofa::gui::component::performer::BodyPicked &picked) = 0;
3736
virtual void freeTrackedPoint() = 0;
3837
virtual void addCuttingPoint() = 0;
3938
};
@@ -60,11 +59,11 @@ class AdaptiveCuttingController : public Controller, public CuttingAdapter
6059

6160
typedef sofa::core::topology::BaseMeshTopology::Edge Edge;
6261
typedef sofa::core::topology::BaseMeshTopology::EdgesAroundVertex EdgesAroundVertex;
63-
typedef sofa::component::topology::TriangleSetTopologyContainer::TriangleID Index;
64-
typedef sofa::component::topology::TriangleSetTopologyContainer::Triangle Triangle;
65-
typedef sofa::component::topology::TriangleSetTopologyContainer::TrianglesAroundVertex TrianglesAroundVertex;
66-
typedef sofa::component::topology::TriangleSetTopologyContainer::TrianglesAroundEdge TrianglesAroundEdge;
67-
typedef sofa::component::topology::TriangleSetTopologyContainer::EdgesInTriangle EdgesInTriangle;
62+
typedef sofa::component::topology::container::dynamic::TriangleSetTopologyContainer::TriangleID Index;
63+
typedef sofa::component::topology::container::dynamic::TriangleSetTopologyContainer::Triangle Triangle;
64+
typedef sofa::component::topology::container::dynamic::TriangleSetTopologyContainer::TrianglesAroundVertex TrianglesAroundVertex;
65+
typedef sofa::component::topology::container::dynamic::TriangleSetTopologyContainer::TrianglesAroundEdge TrianglesAroundEdge;
66+
typedef sofa::component::topology::container::dynamic::TriangleSetTopologyContainer::EdgesInTriangle EdgesInTriangle;
6867
typedef sofa::type::vector<Index> VecIndex;
6968

7069
enum { InvalidID = sofa::core::topology::Topology::InvalidID };
@@ -76,23 +75,13 @@ class AdaptiveCuttingController : public Controller, public CuttingAdapter
7675
virtual void init();
7776
virtual void reinit();
7877

79-
virtual std::string getTemplateName() const
80-
{
81-
return templateName(this);
82-
}
83-
84-
static std::string templateName(const AdaptiveCuttingController<DataTypes>* = NULL)
85-
{
86-
return DataTypes::Name();
87-
}
88-
8978
void onEndAnimationStep(const double dt);
9079
//void onKeyPressedEvent(core::objectmodel::KeypressedEvent *key);
9180

9281
void draw(const core::visual::VisualParams* vparams);
9382

9483

95-
void setTrackedPoint(const collision::BodyPicked &picked);
84+
void setTrackedPoint(const sofa::gui::component::performer::BodyPicked &picked);
9685
void freeTrackedPoint() {
9786
// Detach the point
9887
m_pointId = InvalidID;
@@ -113,9 +102,8 @@ class AdaptiveCuttingController : public Controller, public CuttingAdapter
113102
private:
114103

115104
Test2DAdapter<DataTypes>* m_adapter;
116-
sofa::component::topology::TriangleSetTopologyContainer* m_container;
117-
sofa::component::topology::TriangleSetGeometryAlgorithms<DataTypes> *m_algoGeom;
118-
sofa::component::topology::TriangleSetTopologyAlgorithms<DataTypes> *m_algoTopo;
105+
sofa::component::topology::container::dynamic::TriangleSetTopologyContainer* m_container;
106+
sofa::component::topology::container::dynamic::TriangleSetGeometryAlgorithms<DataTypes> *m_algoGeom;
119107
sofa::core::behavior::MechanicalState<DataTypes>* m_state;
120108

121109
// TODO: This should go to cutting config (maybe?)

src/Shell/controller/AdaptiveCuttingController.inl renamed to extensions/Shell.Adaptivity/src/Shell/Adaptivity/controller/AdaptiveCuttingController.inl

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
// TODO
55
// - protect/unprotect cut edges (m_cutEdge,m_cutList)
66

7-
#include <SofaShells/config.h>
7+
#include <Shell/Adaptivity/config.h>
88

99
#include <float.h>
1010
#include <sofa/helper/rmath.h>
1111

12-
#include <SofaShells/misc/PointProjection.h>
13-
#include <SofaShells/controller/AdaptiveCuttingController.h>
14-
#include <SofaMeshCollision/TriangleModel.h>
12+
#include <Shell/Adaptivity/controller/AdaptiveCuttingController.h>
13+
#include <Shell/misc/PointProjection.h>
14+
#include <sofa/component/collision/geometry/TriangleModel.h>
1515

1616
#define OTHER(x, a, b) ((x == a) ? b : a)
1717

@@ -75,12 +75,6 @@ void AdaptiveCuttingController<DataTypes>::init()
7575
return;
7676
}
7777

78-
this->getContext()->get(m_algoTopo);
79-
if (m_algoTopo == NULL) {
80-
msg_error() << "Unable to find TriangleSetTopologyAlgorithms";
81-
return;
82-
}
83-
8478
reinit();
8579
}
8680

@@ -105,7 +99,7 @@ void AdaptiveCuttingController<DataTypes>::onEndAnimationStep(const double /*dt*
10599
if (m_gracePeriod > 0) m_gracePeriod--;
106100

107101
const VecCoord& x0 = m_state->read(
108-
sofa::core::ConstVecCoordId::restPosition())->getValue();
102+
sofa::core::vec_id::read_access::restPosition)->getValue();
109103

110104
// Perform the (delayed) cutting
111105
if ((m_cutList.size() > 0) && (m_cutPoints > 2) ) {
@@ -117,7 +111,7 @@ void AdaptiveCuttingController<DataTypes>::onEndAnimationStep(const double /*dt*
117111
}
118112
// Then perform the incision
119113
bool bReachedBorder;
120-
m_algoTopo->InciseAlongEdgeList(m_cutList, newList, endList,
114+
m_algoGeom->InciseAlongEdgeList(m_cutList, newList, endList,
121115
bReachedBorder);
122116
//m_algoTopo->InciseAlongEdge(m_cutList[0], NULL);
123117
m_cutList.clear();
@@ -161,10 +155,10 @@ void AdaptiveCuttingController<DataTypes>::draw(
161155
return;
162156

163157
if (!m_state) return;
164-
const VecCoord& x = m_state->read(sofa::core::ConstVecCoordId::position())->getValue();
158+
const VecCoord& x = m_state->read(sofa::core::vec_id::read_access::position)->getValue();
165159

166160
if (m_cutList.size() > 0) {
167-
type::vector<type::Vector3> points;
161+
type::vector<type::Vec3> points;
168162
for (VecIndex::const_iterator i=m_cutList.begin();
169163
i != m_cutList.end(); i++) {
170164
const Edge &e = m_container->getEdge(*i);
@@ -177,7 +171,7 @@ void AdaptiveCuttingController<DataTypes>::draw(
177171

178172
if (m_cutEdge != InvalidID) {
179173
const Edge &e = m_container->getEdge(m_cutEdge);
180-
type::vector<type::Vector3> points;
174+
type::vector<type::Vec3> points;
181175
points.push_back(x[ e[0] ]);
182176
points.push_back(x[ e[1] ]);
183177
vparams->drawTool()->drawLines(points, 4,
@@ -188,16 +182,16 @@ void AdaptiveCuttingController<DataTypes>::draw(
188182

189183
template<class DataTypes>
190184
void AdaptiveCuttingController<DataTypes>::setTrackedPoint(
191-
const collision::BodyPicked &picked)
185+
const sofa::gui::component::performer::BodyPicked &picked)
192186
{
193187
if (!m_adapter) return;
194188

195189
using namespace sofa::component::collision;
196190

197191
//const VecCoord& x0 = m_state->read(
198-
// sofa::core::ConstVecCoordId::restPosition())->getValue();
192+
// sofa::core::vec_id::read_access::restPosition)->getValue();
199193
const VecCoord& x = m_state->read(
200-
sofa::core::ConstVecCoordId::position())->getValue();
194+
sofa::core::vec_id::read_access::position)->getValue();
201195

202196

203197
// Support only trianglular model! The others don't give any added value.
@@ -211,7 +205,7 @@ void AdaptiveCuttingController<DataTypes>::setTrackedPoint(
211205
Real d2 = (x[ e[1] ] - m_point).norm2();
212206
m_pointId = (d1 < d2 ? e[0] : e[1]);
213207
} else*/
214-
if(dynamic_cast<TriangleModel*>(picked.body)) {
208+
if(dynamic_cast<geometry::TriangleCollisionModel<DataTypes> *>(picked.body)) {
215209

216210
Index newId = InvalidID;
217211
Index newCutEdge = InvalidID;
@@ -350,17 +344,17 @@ template<class DataTypes>
350344
void AdaptiveCuttingController<DataTypes>::addCuttingPoint()
351345
{
352346
if (!m_adapter) return;
353-
if (!m_algoTopo || !m_algoGeom) return;
347+
if (!m_algoGeom) return;
354348

355349
if (m_pointId == InvalidID) {
356350
msg_error() << "BUG! Attempted cutting with no point tracked.";
357351
return;
358352
}
359353

360354
const VecCoord& x = m_state->read(
361-
sofa::core::ConstVecCoordId::position())->getValue();
355+
sofa::core::vec_id::read_access::position)->getValue();
362356
//const VecCoord& xrest = m_state->read(
363-
// sofa::core::ConstVecCoordId::restPosition())->getValue();
357+
// sofa::core::vec_id::read_access::restPosition)->getValue();
364358
Coord oldpos = x[m_pointId];
365359

366360
bool bFirst = !cutting();

0 commit comments

Comments
 (0)