Commit f33f9825 authored by Alexis Girault's avatar Alexis Girault
Browse files

STYLE: Update functions order in geometry

1) Clean up print methods
2) Put initialize, print, clear, getVolume on top
3) Add missing overrides
4) Replace extractSurfaceMesh by computeAttachedSurfaceMesh
5) Define Mesh::print
6) Use Mesh::clear in subclasses
parent 12be8dec
......@@ -27,8 +27,13 @@ void
Cube::print() const
{
Geometry::print();
LOG(INFO) << "Width: " << m_width;
}
LOG(INFO) << "Width: " << m_width << "\n";
double
Cube::getVolume() const
{
return m_width*m_width;
}
const double&
......@@ -43,10 +48,4 @@ Cube::setWidth(const double& width)
m_width = width;
}
double
Cube::getVolume() const
{
return m_width*m_width;
}
}
......@@ -46,14 +46,14 @@ public:
~Cube() = default;
///
/// \brief Returns the volume of the cube
/// \brief Print the cube info
///
double getVolume() const;
void print() const;
///
/// \brief Print the cube info
/// \brief Returns the volume of the cube
///
void print() const;
double getVolume() const override;
// Accessors
///
......
......@@ -27,8 +27,13 @@ void
Plane::print() const
{
Geometry::print();
LOG(INFO) << "Width: " << m_width;
}
LOG(INFO) << "Width: " << m_width << "\n";
double
Plane::getVolume() const
{
return 0.0;
}
Vec3d
......@@ -54,10 +59,4 @@ Plane::setWidth(const double& width)
{
m_width = width;
}
double
Plane::getVolume() const
{
return 0.0;
}
}
......@@ -51,15 +51,21 @@ public:
///
void print() const override;
///
/// \brief Returns the volume (=0.0) for the plane
///
double getVolume() const override;
// Accessors
///
/// \brief Returns the normal of the plane
///
Vec3d getNormal() const;
Vec3d getNormal() const;
///
/// \brief Sets the normal to the plane
///
void setNormal(const Vec3d& normal);
void setNormal(const Vec3d& normal);
///
/// \brief Returns the width of the plane
......@@ -69,12 +75,8 @@ public:
///
/// \brief Sets the width of the plane
///
void setWidth(const double& width);
void setWidth(const double& width);
///
/// \brief Returns the volume (=0.0) for the plane
///
double getVolume() const;
protected:
double m_width; ///> Width of the plane (for display)
......
......@@ -27,8 +27,13 @@ void
Sphere::print() const
{
Geometry::print();
LOG(INFO) << "Radius: " << m_radius;
}
LOG(INFO) << "Radius: " << m_radius << "\n";
double
Sphere::getVolume() const
{
return 0.75*PI*m_radius*m_radius*m_radius;
}
const double&
......@@ -42,11 +47,4 @@ Sphere::setRadius(const double& radius)
{
m_radius = radius;
}
double
Sphere::getVolume() const
{
return 0.75*PI*m_radius*m_radius*m_radius;
}
}
......@@ -50,6 +50,12 @@ public:
///
void print() const override;
///
/// \brief Returns the volume of the sphere
///
double getVolume() const override;
// Accessors
///
/// \brief Returns the radius of the sphere
///
......@@ -58,12 +64,8 @@ public:
///
/// \brief Sets the radius of the sphere
///
void setRadius(const double& radius);
void setRadius(const double& radius);
///
/// \brief Returns the volume of the sphere
///
double getVolume() const;
protected:
double m_radius; ///> Radius of the sphere
......
......@@ -80,7 +80,9 @@ public:
void setSlave(std::shared_ptr<Geometry> slave) override;
protected:
std::map<int, int> m_oneToOneMap; ///> One to one mapping data
};
}
......
......@@ -22,52 +22,35 @@
#include "imstkHexahedralMesh.h"
namespace imstk {
void
HexahedralMesh::print() const
HexahedralMesh::initialize(const std::vector<Vec3d>& vertices,
const std::vector<HexaArray>& hexahedra)
{
Geometry::print();
LOG(INFO) << "Number of vertices: " << this->getNumVertices() << "\n";
LOG(INFO) << "Number of Hexahedra: " << this->getNumHexahedra() << "\n";
LOG(INFO) << "Hexahedra:\n";
for (auto &hexVerts : this->getHexahedraVertices())
{
LOG(INFO) << "(" << hexVerts[0] << ", " << hexVerts[1] << "," << hexVerts[2] <<
hexVerts[3] << ", " << hexVerts[4] << "," << hexVerts[5] << ", " <<
hexVerts[6] << "," << hexVerts[7] << ")\n";
}
LOG(INFO) << "Vertex positions:\n";
for (auto &verts : this->getVerticesPositions())
{
LOG(INFO) << "(" << verts.x() << ", " << verts.y() << "," << verts.z() << ")\n";
}
Mesh::initialize(vertices);
this->setHexahedraVertices(hexahedra);
}
void
HexahedralMesh::setHexahedraVertices(const std::vector<HexaArray>& hexahedra)
{
m_hexahedraVertices = hexahedra;
}
const std::vector<HexahedralMesh::HexaArray>&
HexahedralMesh::getHexahedraVertices() const
HexahedralMesh::clear()
{
return m_hexahedraVertices;
Mesh::clear();
m_hexahedraVertices.clear();
}
const HexahedralMesh::HexaArray&
HexahedralMesh::getHexahedronVertices(const int& hexaNum) const
void
HexahedralMesh::print() const
{
return m_hexahedraVertices.at(hexaNum);
}
Geometry::print();
int
HexahedralMesh::getNumHexahedra() const
{
return m_hexahedraVertices.size();
LOG(INFO) << "Number of Hexahedra: " << this->getNumHexahedra();
LOG(INFO) << "Hexahedra:";
for (auto &hex : m_hexahedraVertices)
{
LOG(INFO) << hex.at(0) << ", " << hex.at(1) << ", "
<< hex.at(2) << ", " << hex.at(3) << ", "
<< hex.at(4) << ", " << hex.at(5) << ", "
<< hex.at(6) << ", " << hex.at(7);
}
}
double
......@@ -115,4 +98,34 @@ HexahedralMesh::getVolume() const
return volume/6;
}
void
HexahedralMesh::computeAttachedSurfaceMesh()
{
LOG(WARNING) << "HexahedralMesh::computeAttachedSurfaceMesh error: not implemented.";
}
void
HexahedralMesh::setHexahedraVertices(const std::vector<HexaArray>& hexahedra)
{
m_hexahedraVertices = hexahedra;
}
const std::vector<HexahedralMesh::HexaArray>&
HexahedralMesh::getHexahedraVertices() const
{
return m_hexahedraVertices;
}
const HexahedralMesh::HexaArray&
HexahedralMesh::getHexahedronVertices(const int& hexaNum) const
{
return m_hexahedraVertices.at(hexaNum);
}
int
HexahedralMesh::getNumHexahedra() const
{
return m_hexahedraVertices.size();
}
}
......@@ -43,13 +43,35 @@ public:
~HexahedralMesh() = default;
// Accessors
///
/// \brief Initializes the rest of the data structures given vertex positions and
/// hexahedra connectivity
///
void initialize(const std::vector<Vec3d>& vertices,
const std::vector<HexaArray>& hexahedra);
///
/// \brief Clear all the mesh data
///
void clear();
///
/// \brief Print the hexahedral mesh
///
void print() const override;
///
/// \brief Compute and return the volume of the hexahedral mesh
///
double getVolume() const override;
///
/// \brief Computes the attached surface mesh
///
void computeAttachedSurfaceMesh() override;
// Accessors
///
/// \brief Sets/Returns the hexahedral connectivity
///
......@@ -66,11 +88,6 @@ public:
///
int getNumHexahedra() const;
///
/// \brief Compute and return the volume of the hexahedral mesh
///
double getVolume() const;
protected:
std::vector<HexaArray> m_hexahedraVertices; ///< vertices of the hexahedra
......
......@@ -22,6 +22,60 @@
#include "imstkMesh.h"
namespace imstk {
void
Mesh::initialize(const std::vector<Vec3d>& vertices)
{
this->setInitialVerticesPositions(vertices);
this->setVerticesPositions(vertices);
}
void
Mesh::clear()
{
m_initialVerticesPositions.clear();
m_verticesPositions.clear();
m_verticesDisplacements.clear();
}
void
Mesh::print() const
{
Geometry::print();
LOG(INFO) << "Number of vertices: " << this->getNumVertices();
LOG(INFO) << "Vertex positions:";
for (auto &verts : m_verticesPositions)
{
LOG(INFO) << verts.x() << ", " << verts.y() << ", " << verts.z();
}
}
void
Mesh::computeBoundingBox(Vec3d& min, Vec3d& max, const double percent) const
{
min = Vec3d(MAX_D, MAX_D, MAX_D);
max = Vec3d(MIN_D, MIN_D, MIN_D);
for (auto& pos : m_verticesPositions)
{
for (int i = 0; i < 3; ++i)
{
min[i] = std::min(min[i], pos[i]);
max[i] = std::max(max[i], pos[i]);
}
}
if (percent == 0.0)
{
return;
}
else
{
Vec3d range = max - min;
min = min - range*(percent / 100);
max = max + range*(percent / 100);
}
}
void
Mesh::setInitialVerticesPositions(const std::vector<Vec3d>& vertices)
{
......@@ -86,45 +140,4 @@ Mesh::getNumVertices() const
{
return m_initialVerticesPositions.size();
}
void
Mesh::computeBoundingBox(Vec3d& min, Vec3d& max, const double percent) const
{
min = Vec3d(std::numeric_limits<double>::max(),
std::numeric_limits<double>::max(),
std::numeric_limits<double>::max());
max = Vec3d(std::numeric_limits<double>::min(),
std::numeric_limits<double>::min(),
std::numeric_limits<double>::min());
for (auto& pos : m_verticesPositions)
{
for (int i = 0; i < 3; ++i)
{
min[i] = std::min(min[i], pos[i]);
max[i] = std::max(max[i], pos[i]);
}
}
if (percent == 0.0)
{
return;
}
else
{
Vec3d range = max - min;
min = min - range*(percent / 100);
max = max + range*(percent / 100);
}
}
void
Mesh::clear()
{
m_initialVerticesPositions.clear();
m_verticesPositions.clear();
m_verticesDisplacements.clear();
}
}
......@@ -38,15 +38,25 @@ public:
~Mesh() = default;
///
/// \brief Compute the bounding box for the entire mesh
/// \brief Initializes the data structure given vertex positions
///
void computeBoundingBox(Vec3d& min, Vec3d& max, const double percent = 0.0) const;
void initialize(const std::vector<Vec3d>& vertices);
///
/// \brief Clears all the mesh data
///
virtual void clear();
///
/// \brief Print the mesh info
///
virtual void print() const override;
///
/// \brief Compute the bounding box for the entire mesh
///
void computeBoundingBox(Vec3d& min, Vec3d& max, const double percent = 0.0) const;
// Accessors
///
......@@ -103,6 +113,7 @@ public:
/// \brief Returns the number of total vertices in the mesh
///
const int getNumVertices() const;
protected:
Mesh(GeometryType type) : Geometry(type, WORLD_ORIGIN, Quatd()) {}
......
......@@ -22,31 +22,62 @@
#include "imstkSurfaceMesh.h"
namespace imstk {
void
SurfaceMesh::initialize(const std::vector<Vec3d>& vertices,
const std::vector<TriangleArray>& triangles,
const std::vector<Vec2f>& texCoords,
const bool computDerivedData)
const std::vector<TriangleArray>& triangles,
const std::vector<Vec2f>& texCoords,
const bool computeDerivedData)
{
this->clear();
setInitialVerticesPositions(vertices);
setVerticesPositions(vertices);
Mesh::initialize(vertices);
setTrianglesVertices(triangles);
setTextureCoordinates(texCoords);
if (texCoords.size() > 0)
if (computeDerivedData)
{
setTextureCoordinates(texCoords);
computeVerticesNormals();
computeVerticesTangents();
}
}
if (computDerivedData)
void
SurfaceMesh::clear()
{
Mesh::clear();
m_trianglesVertices.clear();
m_textureCoordinates.clear();
m_verticesNeighborTriangles.clear();
m_verticesNeighborVertices.clear();
m_trianglesNormals.clear();
m_verticesNormals.clear();
m_verticesTangents.clear();
}
void
SurfaceMesh::print() const
{
Mesh::print();
LOG(INFO) << "Number of triangles: " << this->getNumTriangles();
LOG(INFO) << "Triangles:";
for (auto &tri : m_trianglesVertices)
{
computeVerticesNormals();
computeTrianglesNormals();
computeVerticesTangents();
LOG(INFO) << tri.at(0) << ", " << tri.at(1) << ", " << tri.at(2);
}
}
double
SurfaceMesh::getVolume() const
{
// TODO
// 1. Check for water tightness
// 2. Compute volume based on signed distance
LOG(WARNING) << "SurfaceMesh::getVolume error: not implemented.";
return 0.0;
}
void
SurfaceMesh::computeVerticesNeighborTriangles()
{
......@@ -214,125 +245,6 @@ SurfaceMesh::computeVerticesTangents()
}
}
const std::vector<SurfaceMesh::TriangleArray>&
SurfaceMesh::getTrianglesVertices() const
{
return m_trianglesVertices;
}
void
SurfaceMesh::setTrianglesVertices(const std::vector<TriangleArray>& triangles)
{
m_trianglesVertices = triangles;
}
const std::vector<Vec2f>&
SurfaceMesh::getTextureCoordinates() const
{
return m_textureCoordinates;
}
void
SurfaceMesh::setTextureCoordinates(const std::vector<Vec2f>& coords)
{
m_textureCoordinates = coords;
}
const Vec2f&
SurfaceMesh::getVertTextureCoordinate(const int vertNum) const
{
return m_textureCoordinates.at(vertNum);
}
const std::vector<Vec3d>&
SurfaceMesh::getTrianglesNormals() const
{
return m_trianglesNormals;
}
const Vec3d&
SurfaceMesh::getTriangleNormal(size_t i) const
{
return m_trianglesNormals.at(i);
}
const std::vector<Vec3d>&
SurfaceMesh::getVerticesNormals() const
{
return m_verticesNormals;
}
const Vec3d&
SurfaceMesh::getVerticeNormal(size_t i) const
{
return m_verticesNormals.at(i);
}
const std::vector<Vec4d>&
SurfaceMesh::getVerticesTangents() const
{
return m_verticesTangents;
}
int
SurfaceMesh::getNumTriangles() const