Skip to content
Draft
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
2 changes: 2 additions & 0 deletions Sofa/Component/Topology/Container/Constant/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ set(HEADER_FILES
${SOFACOMPONENTTOPOLOGYCONTAINERCONSTANT_SOURCE_DIR}/config.h.in
${SOFACOMPONENTTOPOLOGYCONTAINERCONSTANT_SOURCE_DIR}/init.h
${SOFACOMPONENTTOPOLOGYCONTAINERCONSTANT_SOURCE_DIR}/MeshTopology.h
${SOFACOMPONENTTOPOLOGYCONTAINERCONSTANT_SOURCE_DIR}/MeshTopologyContainer.h
${SOFACOMPONENTTOPOLOGYCONTAINERCONSTANT_SOURCE_DIR}/CubeTopology.h
${SOFACOMPONENTTOPOLOGYCONTAINERCONSTANT_SOURCE_DIR}/SphereQuadTopology.h
)

set(SOURCE_FILES
${SOFACOMPONENTTOPOLOGYCONTAINERCONSTANT_SOURCE_DIR}/init.cpp
${SOFACOMPONENTTOPOLOGYCONTAINERCONSTANT_SOURCE_DIR}/MeshTopology.cpp
${SOFACOMPONENTTOPOLOGYCONTAINERCONSTANT_SOURCE_DIR}/MeshTopologyContainer.cpp
${SOFACOMPONENTTOPOLOGYCONTAINERCONSTANT_SOURCE_DIR}/CubeTopology.cpp
${SOFACOMPONENTTOPOLOGYCONTAINERCONSTANT_SOURCE_DIR}/SphereQuadTopology.cpp
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,16 @@ MeshTopology::EdgeUpdate::EdgeUpdate(MeshTopology* t)
{
if( topology->hasVolume() )
{
addInput(&topology->d_seqHexahedra);
addInput(&topology->d_seqTetrahedra);
addOutput(&topology->d_seqEdges);
addInput(&topology->d_seqHexahedra.toData());
addInput(&topology->d_seqTetrahedra.toData());
addOutput(&topology->d_seqEdges.toData());
setDirtyValue();
}
else if( topology->hasSurface() )
{
addInput(&topology->d_seqTriangles);
addInput(&topology->d_seqQuads);
addOutput(&topology->d_seqEdges);
addInput(&topology->d_seqTriangles.toData());
addInput(&topology->d_seqQuads.toData());
addOutput(&topology->d_seqEdges.toData());
setDirtyValue();
}

Expand Down Expand Up @@ -221,8 +221,8 @@ void MeshTopology::EdgeUpdate::updateFromSurface()
MeshTopology::TriangleUpdate::TriangleUpdate(MeshTopology *t)
:PrimitiveUpdate(t)
{
addInput(&topology->d_seqTetrahedra);
addOutput(&topology->d_seqTriangles);
addInput(&topology->d_seqTetrahedra.toData());
addOutput(&topology->d_seqTriangles.toData());
setDirtyValue();
}

Expand Down Expand Up @@ -275,8 +275,8 @@ void MeshTopology::TriangleUpdate::doUpdate()
MeshTopology::QuadUpdate::QuadUpdate(MeshTopology *t)
:PrimitiveUpdate(t)
{
addInput(&topology->d_seqHexahedra);
addOutput(&topology->d_seqQuads);
addInput(&topology->d_seqHexahedra.toData());
addOutput(&topology->d_seqQuads.toData());
setDirtyValue();
}

Expand Down Expand Up @@ -486,13 +486,6 @@ void registerMeshTopology(sofa::core::ObjectFactory* factory)

MeshTopology::MeshTopology()
: d_seqPoints(initData(&d_seqPoints, "position", "List of point positions"))
, d_seqEdges(initData(&d_seqEdges, "edges", "List of edge indices"))
, d_seqTriangles(initData(&d_seqTriangles, "triangles", "List of triangle indices"))
, d_seqQuads(initData(&d_seqQuads, "quads", "List of quad indices"))
, d_seqTetrahedra(initData(&d_seqTetrahedra, "tetrahedra", "List of tetrahedron indices"))
, d_seqHexahedra(initData(&d_seqHexahedra, "hexahedra", "List of hexahedron indices"))
, d_seqPrisms(initData(&d_seqPrisms, "prisms", "List of prisms indices"))
, d_seqPyramids(initData(&d_seqPyramids, "pyramids", "List of pyramids indices"))
, d_seqUVs(initData(&d_seqUVs, "uv", "List of uv coordinates"))
, d_computeAllBuffers(initData(&d_computeAllBuffers, false, "computeAllBuffers", "Option to compute all crossed topology buffers at init. False by default"))
, nbPoints(0)
Expand All @@ -506,9 +499,9 @@ MeshTopology::MeshTopology()
{
m_upperElementType = sofa::geometry::ElementType::EDGE;
addAlias(&d_seqPoints, "points");
addAlias(&d_seqEdges, "lines");
addAlias(&d_seqTetrahedra, "tetras");
addAlias(&d_seqHexahedra, "hexas");
addAlias(&d_seqEdges.toData(), "lines");
addAlias(&d_seqTetrahedra.toData(), "tetras");
addAlias(&d_seqHexahedra.toData(), "hexas");
addAlias(&d_seqUVs, "texcoords");
}

Expand Down Expand Up @@ -747,51 +740,6 @@ void MeshTopology::addUV(SReal u, SReal v)
nbPoints = (int)d_seqUVs.getValue().size();
}

const MeshTopology::SeqEdges& MeshTopology::getEdges()
{
return d_seqEdges.getValue();
}

const MeshTopology::SeqTriangles& MeshTopology::getTriangles()
{
return d_seqTriangles.getValue();
}

const MeshTopology::SeqQuads& MeshTopology::getQuads()
{
return d_seqQuads.getValue();
}

const MeshTopology::SeqTetrahedra& MeshTopology::getTetrahedra()
{
if (!validTetrahedra)
{
updateTetrahedra();
validTetrahedra = true;
}
return d_seqTetrahedra.getValue();
}

const MeshTopology::SeqHexahedra& MeshTopology::getHexahedra()
{
if (!validHexahedra)
{
updateHexahedra();
validHexahedra = true;
}
return d_seqHexahedra.getValue();
}

const BaseMeshTopology::SeqPrisms& MeshTopology::getPrisms()
{
return d_seqPrisms.getValue();
}

const BaseMeshTopology::SeqPyramids& MeshTopology::getPyramids()
{
return d_seqPyramids.getValue();
}

const MeshTopology::SeqUV& MeshTopology::getUVs()
{
return d_seqUVs.getValue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@
#include <sofa/component/topology/container/constant/config.h>

#include <sofa/core/topology/Topology.h>
#include <sofa/core/topology/BaseMeshTopology.h>
#include <sofa/component/topology/container/constant/MeshTopologyContainer.h>
#include <sofa/core/DataEngine.h>
#include <sofa/type/vector.h>

namespace sofa::component::topology::container::constant
{

class SOFA_COMPONENT_TOPOLOGY_CONTAINER_CONSTANT_API MeshTopology : public core::topology::BaseMeshTopology
class SOFA_COMPONENT_TOPOLOGY_CONTAINER_CONSTANT_API MeshTopology : public MeshTopologyContainer
{
public:
SOFA_CLASS(MeshTopology,core::topology::BaseMeshTopology);
SOFA_CLASS(MeshTopology, MeshTopologyContainer);
protected:

class PrimitiveUpdate : public sofa::core::DataEngine
Expand Down Expand Up @@ -91,16 +91,6 @@ class SOFA_COMPONENT_TOPOLOGY_CONTAINER_CONSTANT_API MeshTopology : public core:

void setNbPoints(Size n) override;

// Complete sequence accessors

const SeqEdges& getEdges() override;
const SeqTriangles& getTriangles() override;
const SeqQuads& getQuads() override;
const SeqTetrahedra& getTetrahedra() override;
const SeqHexahedra& getHexahedra() override;
const SeqPrisms& getPrisms() override;
const SeqPyramids& getPyramids() override;

// If using STEP loader, include also uv coordinates
typedef Index UVID;
typedef type::Vec2 UV;
Expand Down Expand Up @@ -297,17 +287,19 @@ class SOFA_COMPONENT_TOPOLOGY_CONTAINER_CONSTANT_API MeshTopology : public core:
typedef type::vector<type::Vec3> SeqPoints;

Data< SeqPoints > d_seqPoints; ///< List of point positions
Data<SeqEdges> d_seqEdges; ///< List of edge indices
Data<SeqTriangles> d_seqTriangles; ///< List of triangle indices
Data<SeqQuads> d_seqQuads; ///< List of quad indices
Data<SeqTetrahedra> d_seqTetrahedra; ///< List of tetrahedron indices
Data<SeqHexahedra> d_seqHexahedra; ///< List of hexahedron indices
Data<SeqPrisms> d_seqPrisms;
Data<SeqPyramids> d_seqPyramids;
SeqElementProxy<sofa::geometry::Edge> d_seqEdges { this };
SeqElementProxy<sofa::geometry::Triangle> d_seqTriangles { this };
SeqElementProxy<sofa::geometry::Quad> d_seqQuads { this };
SeqElementProxy<sofa::geometry::Tetrahedron> d_seqTetrahedra { this };
SeqElementProxy<sofa::geometry::Hexahedron> d_seqHexahedra { this };
SeqElementProxy<sofa::geometry::Prism> d_seqPrisms { this };
SeqElementProxy<sofa::geometry::Pyramid> d_seqPyramids { this };

Data<SeqUV> d_seqUVs; ///< List of uv coordinates
Data<bool> d_computeAllBuffers; ///< Option to call method computeCrossElementBuffers. False by default

protected:

Size nbPoints;

template<typename ElementContainer>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
/******************************************************************************
* SOFA, Simulation Open-Framework Architecture *
* (c) 2006 INRIA, USTL, UJF, CNRS, MGH *
* *
* This program 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 2.1 of the License, or (at *
* your option) any later version. *
* *
* This program 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 program. If not, see <http://www.gnu.org/licenses/>. *
*******************************************************************************
* Authors: The SOFA Team and external contributors (see Authors.txt) *
* *
* Contact information: contact@sofa-framework.org *
******************************************************************************/
#include <sofa/component/topology/container/constant/MeshTopologyContainer.h>

namespace sofa::component::topology::container::constant
{

using sofa::geometry::ElementType;

constexpr const char* elementTypeToDataName(ElementType type)
{
switch (type)
{
case ElementType::POINT: { return "position"; }
case ElementType::EDGE: { return "edges"; }
case ElementType::TRIANGLE: { return "triangles"; }
case ElementType::QUAD: { return "quads"; }
case ElementType::TETRAHEDRON: { return "tetrahedra"; }
case ElementType::HEXAHEDRON: { return "hexahedra"; }
case ElementType::PRISM: { return "prisms"; }
case ElementType::PYRAMID: { return "pyramids"; }

case ElementType::QUADRATIC_EDGE: { return "quadratic_edges"; }
case ElementType::QUADRATIC_TRIANGLE: { return "quadratic_triangles"; }
case ElementType::QUADRATIC_QUAD: { return "quadratic_quads"; }
case ElementType::QUADRATIC_TETRAHEDRON: { return "quadratic_tetrahedra"; }
case ElementType::QUADRATIC_HEXAHEDRON: { return "quadratic_hexahedra"; }
case ElementType::QUADRATIC_PRISM: { return "quadratic_prisms"; }
case ElementType::QUADRATIC_PYRAMID: { return "quadratic_pyramids"; }

default:
return "Unknown";
}
}
template<std::size_t I>
void registerSingleData(core::objectmodel::BaseComponent* meshTopology, auto& dataContainer)
{
using AllElements = std::remove_cvref_t<decltype(dataContainer)>;
using DataSeqElementPtr = std::tuple_element_t<I, AllElements>;
using DataSeqElement = typename DataSeqElementPtr::element_type;
using SeqElement = typename DataSeqElement::value_type;
using TopologyElement = typename SeqElement::value_type;
static constexpr auto elementType = TopologyElement::Element_type;

const char* elementName = sofa::geometry::elementTypeToString(elementType);
auto elementNameStr = sofa::helper::downcaseString(std::string(elementName));

auto dataName = elementTypeToDataName(elementType);
std::string dataNameStr { dataName };
sofa::helper::replaceAll(dataNameStr, " ", "_");

auto& dataPtr = std::get<I>(dataContainer);
dataPtr = std::make_unique<DataSeqElement>("List of " + elementNameStr);

sofa::core::objectmodel::BaseData& data = *dataPtr;
data.setName(dataName);

meshTopology->addData(dataPtr.get(), dataName);
}

template<size_t... Is>
void registerData(core::objectmodel::BaseComponent* meshTopology, auto& dataContainer, std::index_sequence<Is...>)
{
(registerSingleData<Is>(meshTopology, dataContainer), ...);
}

const void* MeshTopologyContainer::getElementsRaw(
const sofa::geometry::ElementType& elementType) const noexcept
{
switch (elementType)
{
case ElementType::UNKNOWN:
case ElementType::POINT:
break;
case ElementType::EDGE:
return &get<sofa::geometry::Edge>()->getValue();
case ElementType::TRIANGLE:
return &get<sofa::geometry::Triangle>()->getValue();
case ElementType::QUAD:
return &get<sofa::geometry::Quad>()->getValue();
case ElementType::TETRAHEDRON:
return &get<sofa::geometry::Tetrahedron>()->getValue();
case ElementType::HEXAHEDRON:
return &get<sofa::geometry::Hexahedron>()->getValue();
case ElementType::PRISM:
return &get<sofa::geometry::Prism>()->getValue();
case ElementType::PYRAMID:
return &get<sofa::geometry::Pyramid>()->getValue();
case ElementType::QUADRATIC_EDGE:
return &get<sofa::geometry::QuadraticEdge>()->getValue();
case ElementType::QUADRATIC_TRIANGLE:
return &get<sofa::geometry::QuadraticTriangle>()->getValue();
case ElementType::QUADRATIC_QUAD:
return &get<sofa::geometry::QuadraticQuad>()->getValue();
case ElementType::QUADRATIC_TETRAHEDRON:
return &get<sofa::geometry::QuadraticTetrahedron>()->getValue();
case ElementType::QUADRATIC_HEXAHEDRON:
return &get<sofa::geometry::QuadraticHexahedron>()->getValue();
case ElementType::QUADRATIC_PRISM:
return &get<sofa::geometry::QuadraticPrism>()->getValue();
case ElementType::QUADRATIC_PYRAMID:
return &get<sofa::geometry::QuadraticPyramid>()->getValue();
case ElementType::SIZE:
default:
return nullptr;
}
return nullptr;
}

MeshTopologyContainer::MeshTopologyContainer() : Inherit1()
{
registerData(this, m_container, std::make_index_sequence<std::tuple_size_v<AllElements>>{});
}

const core::topology::BaseMeshTopology::SeqEdges& MeshTopologyContainer::getEdges()
{
return get<sofa::geometry::Edge>()->getValue();
}
const core::topology::BaseMeshTopology::SeqTriangles& MeshTopologyContainer::getTriangles()
{
return get<sofa::geometry::Triangle>()->getValue();
}
const core::topology::BaseMeshTopology::SeqQuads& MeshTopologyContainer::getQuads()
{
return get<sofa::geometry::Quad>()->getValue();
}
const core::topology::BaseMeshTopology::SeqTetrahedra& MeshTopologyContainer::getTetrahedra()
{
return get<sofa::geometry::Tetrahedron>()->getValue();
}
const core::topology::BaseMeshTopology::SeqHexahedra& MeshTopologyContainer::getHexahedra()
{
return get<sofa::geometry::Hexahedron>()->getValue();
}
const core::topology::BaseMeshTopology::SeqPrisms& MeshTopologyContainer::getPrisms()
{
return get<sofa::geometry::Prism>()->getValue();
}
const core::topology::BaseMeshTopology::SeqPyramids& MeshTopologyContainer::getPyramids()
{
return get<sofa::geometry::Pyramid>()->getValue();
}

} // namespace sofa::component::topology::container::constant
Loading
Loading