Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 2 additions & 36 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ sofa_find_package(Sofa.GL REQUIRED)

set(README_FILE README.md)

option(SOFA-PLUGIN_SHELLS_ADAPTIVITY "Enables shells adaptivity" OFF)

# List all files
set(SHELL_SRC_DIR src/Shell)
set(HEADER_FILES
Expand Down Expand Up @@ -70,40 +68,6 @@ set(SOURCE_FILES
${SHELL_SRC_DIR}/shells2/mapping/BezierShellMechanicalMapping.cpp
)

if(SOFA-PLUGIN_SHELLS_ADAPTIVITY)
set(COMPILER_DEFINE "SOFA_BUILD_SHELLS_ADAPTIVITY")

list(APPEND HEADER_FILES
${SHELL_SRC_DIR}/controller/AdaptiveCuttingController.h
${SHELL_SRC_DIR}/controller/AdaptiveCuttingController.inl
${SHELL_SRC_DIR}/controller/Test2DAdapter.h
${SHELL_SRC_DIR}/controller/Test2DAdapter.inl
${SHELL_SRC_DIR}/misc/Optimize2DSurface.h
${SHELL_SRC_DIR}/misc/Optimize2DSurface.inl
${SHELL_SRC_DIR}/misc/SurfaceParametrization.h
${SHELL_SRC_DIR}/misc/SurfaceParametrization.inl
)

list(APPEND SOURCE_FILES
${SHELL_SRC_DIR}/controller/AdaptiveCuttingController.cpp
${SHELL_SRC_DIR}/controller/Test2DAdapter.cpp
${SHELL_SRC_DIR}/misc/Optimize2DSurface.cpp
${SHELL_SRC_DIR}/misc/SurfaceParametrization.cpp
)

if(SofaGui_FOUND AND SofaOpenglVisual_FOUND)
list(APPEND HEADER_FILES
${SHELL_SRC_DIR}/cutting/AdaptiveCutting.h
)

list(APPEND SOURCE_FILES
${SHELL_SRC_DIR}/cutting/AdaptiveCutting.cpp
)
endif()

endif()


# Create the plugin library
add_library(${PROJECT_NAME} SHARED ${HEADER_FILES} ${SOURCE_FILES} ${README_FILES})

Expand All @@ -124,3 +88,5 @@ sofa_create_package_with_targets(
INCLUDE_INSTALL_DIR ${PROJECT_NAME}
RELOCATABLE "plugins"
)

sofa_add_subdirectory(plugin extensions/Shell.Adaptivity Shell.Adaptivity)
49 changes: 49 additions & 0 deletions extensions/Shell.Adaptivity/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# CMakeLists.txt for Shell.Adaptivity plugin
cmake_minimum_required(VERSION 3.12)
project(Shell.Adaptivity VERSION 1.0 LANGUAGES CXX)

find_package(Sofa.Config REQUIRED)
sofa_find_package(Shell REQUIRED)
sofa_find_package(Sofa.GUI.Component REQUIRED)
sofa_find_package(Sofa.GUI.Common REQUIRED)

set(HEADER_FILES
src/Shell/Adaptivity/config.h.in
src/Shell/Adaptivity/init.h

src/Shell/Adaptivity/controller/AdaptiveCuttingController.h
src/Shell/Adaptivity/controller/AdaptiveCuttingController.inl
src/Shell/Adaptivity/controller/Test2DAdapter.h
src/Shell/Adaptivity/controller/Test2DAdapter.inl

src/Shell/Adaptivity/cutting/AdaptiveCutting.h

src/Shell/Adaptivity/misc/Optimize2DSurface.h
src/Shell/Adaptivity/misc/Optimize2DSurface.inl
src/Shell/Adaptivity/misc/SurfaceParametrization.h
src/Shell/Adaptivity/misc/SurfaceParametrization.inl
)

set(SOURCE_FILES
src/Shell/Adaptivity/init.cpp

src/Shell/Adaptivity/controller/AdaptiveCuttingController.cpp
src/Shell/Adaptivity/controller/Test2DAdapter.cpp

src/Shell/Adaptivity/cutting/AdaptiveCutting.cpp

src/Shell/Adaptivity/misc/Optimize2DSurface.cpp
src/Shell/Adaptivity/misc/SurfaceParametrization.cpp
)

add_library(${PROJECT_NAME} SHARED ${HEADER_FILES} ${SOURCE_FILES})
target_link_libraries(${PROJECT_NAME} PUBLIC Shell Sofa.GUI.Component Sofa.GUI.Common)

sofa_create_package_with_targets(
PACKAGE_NAME ${PROJECT_NAME}
PACKAGE_VERSION ${PROJECT_VERSION}
TARGETS ${PROJECT_NAME} AUTO_SET_TARGET_PROPERTIES
INCLUDE_SOURCE_DIR "src"
INCLUDE_INSTALL_DIR ${PROJECT_NAME}
RELOCATABLE "plugins"
)
12 changes: 12 additions & 0 deletions extensions/Shell.Adaptivity/Shell.AdaptivityConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# CMake package configuration file for the plugin @PROJECT_NAME@

@PACKAGE_GUARD@
@PACKAGE_INIT@

find_package(Shell QUIET REQUIRED)

if(NOT TARGET @PROJECT_NAME@)
include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@Targets.cmake")
endif()

check_required_components(Shell.Adaptivity)
15 changes: 15 additions & 0 deletions extensions/Shell.Adaptivity/src/Shell/Adaptivity/config.h.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#pragma once
#include <sofa/config.h>

#ifdef SOFA_BUILD_SHELL_ADAPTIVITY
# define SOFA_TARGET @PROJECT_NAME@
# define SHELL_ADAPTIVITY_API SOFA_EXPORT_DYNAMIC_LIBRARY
#else
# define SHELL_ADAPTIVITY_API SOFA_IMPORT_DYNAMIC_LIBRARY
#endif

namespace shelladaptivity
{
constexpr const char* MODULE_NAME = "@PROJECT_NAME@";
constexpr const char* MODULE_VERSION = "@PROJECT_VERSION@";
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include <SofaShells/config.h>
#include <SofaShells/cutting/AdaptiveCuttingController.inl>
#include <Shell/Adaptivity/config.h>
#include <Shell/Adaptivity/controller/AdaptiveCuttingController.inl>
#include <sofa/core/ObjectFactory.h>


Expand All @@ -20,20 +20,20 @@ SOFA_DECL_CLASS(AdaptiveCuttingController)
int AdaptiveCuttingControllerClass = core::RegisterObject(
"Controller that handles the cutting method based on mesh adaptivity.")
#ifdef SOFA_FLOAT
.add< AdaptiveCuttingController<type::Vec3fTypes> >(true) // default template
.add< AdaptiveCuttingController<defaulttype::Vec3fTypes> >(true) // default template
#else
.add< AdaptiveCuttingController<type::Vec3dTypes> >(true) // default template
.add< AdaptiveCuttingController<defaulttype::Vec3dTypes> >(true) // default template
# ifndef SOFA_DOUBLE
.add< AdaptiveCuttingController<type::Vec3fTypes> >()
.add< AdaptiveCuttingController<defaulttype::Vec3fTypes> >()
# endif
#endif
;

#ifndef SOFA_FLOAT
template class SOFA_SHELLS_API AdaptiveCuttingController<type::Vec3dTypes>;
template class SHELL_ADAPTIVITY_API AdaptiveCuttingController<defaulttype::Vec3dTypes>;
#endif //SOFA_FLOAT
#ifndef SOFA_DOUBLE
template class SOFA_SHELLS_API AdaptiveCuttingController<type::Vec3fTypes>;
template class SHELL_ADAPTIVITY_API AdaptiveCuttingController<defaulttype::Vec3fTypes>;
#endif //SOFA_DOUBLE

} // namespace controller
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef SOFA_COMPONENT_CONTROLLER_ADAPTIVECUTTINGCONTROLLER_H
#define SOFA_COMPONENT_CONTROLLER_ADAPTIVECUTTINGCONTROLLER_H

#include <SofaUserInteraction/Controller.h>
#include <sofa/component/controller/Controller.h>

#include <sofa/defaulttype/VecTypes.h>
#include <sofa/type/Vec.h>
Expand All @@ -11,14 +11,13 @@
#include <sofa/gui/component/performer/MouseInteractor.h>
#include <sofa/component/topology/container/dynamic/TriangleSetTopologyContainer.h>
#include <sofa/component/topology/container/dynamic/TriangleSetTopologyModifier.h>
#include <sofa/component/topology/container/dynamic/TriangleSetTopologyAlgorithms.h>
#include <sofa/component/topology/container/dynamic/TriangleSetGeometryAlgorithms.h>
#include <sofa/core/topology/TopologyData.h>

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

#include <SofaShells/controller/Test2DAdapter.h>
#include <Shell/Adaptivity/controller/Test2DAdapter.h>

namespace sofa
{
Expand All @@ -33,7 +32,7 @@ namespace controller
class CuttingAdapter
{
public:
virtual void setTrackedPoint(const collision::BodyPicked &picked) = 0;
virtual void setTrackedPoint(const sofa::gui::component::performer::BodyPicked &picked) = 0;
virtual void freeTrackedPoint() = 0;
virtual void addCuttingPoint() = 0;
};
Expand All @@ -60,11 +59,11 @@ class AdaptiveCuttingController : public Controller, public CuttingAdapter

typedef sofa::core::topology::BaseMeshTopology::Edge Edge;
typedef sofa::core::topology::BaseMeshTopology::EdgesAroundVertex EdgesAroundVertex;
typedef sofa::component::topology::TriangleSetTopologyContainer::TriangleID Index;
typedef sofa::component::topology::TriangleSetTopologyContainer::Triangle Triangle;
typedef sofa::component::topology::TriangleSetTopologyContainer::TrianglesAroundVertex TrianglesAroundVertex;
typedef sofa::component::topology::TriangleSetTopologyContainer::TrianglesAroundEdge TrianglesAroundEdge;
typedef sofa::component::topology::TriangleSetTopologyContainer::EdgesInTriangle EdgesInTriangle;
typedef sofa::component::topology::container::dynamic::TriangleSetTopologyContainer::TriangleID Index;
typedef sofa::component::topology::container::dynamic::TriangleSetTopologyContainer::Triangle Triangle;
typedef sofa::component::topology::container::dynamic::TriangleSetTopologyContainer::TrianglesAroundVertex TrianglesAroundVertex;
typedef sofa::component::topology::container::dynamic::TriangleSetTopologyContainer::TrianglesAroundEdge TrianglesAroundEdge;
typedef sofa::component::topology::container::dynamic::TriangleSetTopologyContainer::EdgesInTriangle EdgesInTriangle;
typedef sofa::type::vector<Index> VecIndex;

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

virtual std::string getTemplateName() const
{
return templateName(this);
}

static std::string templateName(const AdaptiveCuttingController<DataTypes>* = NULL)
{
return DataTypes::Name();
}

void onEndAnimationStep(const double dt);
//void onKeyPressedEvent(core::objectmodel::KeypressedEvent *key);

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


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

Test2DAdapter<DataTypes>* m_adapter;
sofa::component::topology::TriangleSetTopologyContainer* m_container;
sofa::component::topology::TriangleSetGeometryAlgorithms<DataTypes> *m_algoGeom;
sofa::component::topology::TriangleSetTopologyAlgorithms<DataTypes> *m_algoTopo;
sofa::component::topology::container::dynamic::TriangleSetTopologyContainer* m_container;
sofa::component::topology::container::dynamic::TriangleSetGeometryAlgorithms<DataTypes> *m_algoGeom;
sofa::core::behavior::MechanicalState<DataTypes>* m_state;

// TODO: This should go to cutting config (maybe?)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
// TODO
// - protect/unprotect cut edges (m_cutEdge,m_cutList)

#include <SofaShells/config.h>
#include <Shell/Adaptivity/config.h>

#include <float.h>
#include <sofa/helper/rmath.h>

#include <SofaShells/misc/PointProjection.h>
#include <SofaShells/controller/AdaptiveCuttingController.h>
#include <SofaMeshCollision/TriangleModel.h>
#include <Shell/Adaptivity/controller/AdaptiveCuttingController.h>
#include <Shell/misc/PointProjection.h>
#include <sofa/component/collision/geometry/TriangleModel.h>

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

Expand Down Expand Up @@ -75,12 +75,6 @@ void AdaptiveCuttingController<DataTypes>::init()
return;
}

this->getContext()->get(m_algoTopo);
if (m_algoTopo == NULL) {
msg_error() << "Unable to find TriangleSetTopologyAlgorithms";
return;
}

reinit();
}

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

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

// Perform the (delayed) cutting
if ((m_cutList.size() > 0) && (m_cutPoints > 2) ) {
Expand All @@ -117,7 +111,7 @@ void AdaptiveCuttingController<DataTypes>::onEndAnimationStep(const double /*dt*
}
// Then perform the incision
bool bReachedBorder;
m_algoTopo->InciseAlongEdgeList(m_cutList, newList, endList,
m_algoGeom->InciseAlongEdgeList(m_cutList, newList, endList,
bReachedBorder);
//m_algoTopo->InciseAlongEdge(m_cutList[0], NULL);
m_cutList.clear();
Expand Down Expand Up @@ -161,10 +155,10 @@ void AdaptiveCuttingController<DataTypes>::draw(
return;

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

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

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

template<class DataTypes>
void AdaptiveCuttingController<DataTypes>::setTrackedPoint(
const collision::BodyPicked &picked)
const sofa::gui::component::performer::BodyPicked &picked)
{
if (!m_adapter) return;

using namespace sofa::component::collision;

//const VecCoord& x0 = m_state->read(
// sofa::core::ConstVecCoordId::restPosition())->getValue();
// sofa::core::vec_id::read_access::restPosition)->getValue();
const VecCoord& x = m_state->read(
sofa::core::ConstVecCoordId::position())->getValue();
sofa::core::vec_id::read_access::position)->getValue();


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

Index newId = InvalidID;
Index newCutEdge = InvalidID;
Expand Down Expand Up @@ -350,17 +344,17 @@ template<class DataTypes>
void AdaptiveCuttingController<DataTypes>::addCuttingPoint()
{
if (!m_adapter) return;
if (!m_algoTopo || !m_algoGeom) return;
if (!m_algoGeom) return;

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

const VecCoord& x = m_state->read(
sofa::core::ConstVecCoordId::position())->getValue();
sofa::core::vec_id::read_access::position)->getValue();
//const VecCoord& xrest = m_state->read(
// sofa::core::ConstVecCoordId::restPosition())->getValue();
// sofa::core::vec_id::read_access::restPosition)->getValue();
Coord oldpos = x[m_pointId];

bool bFirst = !cutting();
Expand Down
Loading
Loading