Skip to content
Open
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: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ CMakeList.txt.user*
/bin
/bii
.vscode
build
build*
77 changes: 77 additions & 0 deletions cmake-lib/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
project(PMUC)
cmake_minimum_required(VERSION 2.8)

# Set C++11 flags to makesome function work
if(UNIX)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -std=gnu++0x")
endif()

set (SRC_LIST
../src/api/rvmcolorhelper.cpp
../src/api/rvmparser.cpp
../src/api/rvmreader.cpp
../src/api/vector3f.cpp
)

set (HEADER_LIST
../src/api/lib_export.h
../src/api/rvmcolorhelper.h
../src/api/rvmparser.h
../src/api/rvmprimitive.h
../src/api/rvmreader.h
../src/api/vector3f.h
)

set (USE_MESH_HELPER TRUE CACHE BOOL
"Indicates whether it is needed to include rvmmeshhelper class in the library")

if (USE_MESH_HELPER)
# Add OpenGL dependencies
set (OpenGL_GL_PREFERENCE LEGACY)
find_package (OpenGL REQUIRED)

list (APPEND SRC_LIST ../src/api/rvmmeshhelper.cpp)
list (APPEND HEADER_LIST ../src/api/rvmmeshhelper.h)

endif()

add_library (${PROJECT_NAME} SHARED "${SRC_LIST}")

set_target_properties (${PROJECT_NAME} PROPERTIES PUBLIC_HEADER "${HEADER_LIST}")


install(TARGETS ${PROJECT_NAME}
CONFIGURATIONS Release
RUNTIME DESTINATION bin
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
PUBLIC_HEADER DESTINATION include/pmuc)

install(TARGETS ${PROJECT_NAME}
CONFIGURATIONS Debug
RUNTIME DESTINATION bind
ARCHIVE DESTINATION libd
LIBRARY DESTINATION libd
PUBLIC_HEADER DESTINATION include/pmuc)

install(TARGETS ${PROJECT_NAME}
CONFIGURATIONS RelWithDebInfo
RUNTIME DESTINATION bini
ARCHIVE DESTINATION libi
LIBRARY DESTINATION libi
PUBLIC_HEADER DESTINATION include/pmuc)

if (WIN32)
install(FILES $<TARGET_PDB_FILE:${PROJECT_NAME}> CONFIGURATIONS Debug
DESTINATION bind OPTIONAL)
install(FILES $<TARGET_PDB_FILE:${PROJECT_NAME}> CONFIGURATIONS RelWithDebInfo
DESTINATION bini OPTIONAL)
endif()

if (USE_MESH_HELPER)
# Include OpenGL lib
target_link_libraries(${PROJECT_NAME} ${OPENGL_LIBRARIES})
endif()

set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 11)
set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD_REQUIRED ON)
11 changes: 11 additions & 0 deletions src/api/lib_export.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#pragma once

#if defined(_WIN32)
#if defined(PMUC_EXPORTS)
#define DLL_PMUC_EXPORT __declspec(dllexport)
#else // !BUILDING_DLL
#define DLL_PMUC_EXPORT __declspec(dllimport)
#endif // BUILDING_DLL
#else // / UNIX /
#define DLL_PMUC_EXPORT
#endif //
6 changes: 4 additions & 2 deletions src/api/rvmcolorhelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,21 @@
#ifndef RVMCOLORHELPER_H
#define RVMCOLORHELPER_H

#include "lib_export.h"

#include <vector>

class RVMColorHelper
{
public:
RVMColorHelper();
DLL_PMUC_EXPORT RVMColorHelper();

/**
* @brief Simple static method to return rgb floats from a PDMS color index. Use the conversion values from Navisworks
* @param index the PDMS material index
* @return RGB floats between 0. and 1.
*/
static const std::vector<float> color(unsigned char index);
DLL_PMUC_EXPORT static const std::vector<float> color(unsigned char index);
};

#endif // RVMCOLORHELPER_H
16 changes: 8 additions & 8 deletions src/api/rvmmeshhelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ static const unsigned long cube_index[] = {0, 1, 2, 2, 3, 0, 4, 7, 5, 5

void CALLBACK tessVertexData(void* vertex_data, void* polygon_data) {
Mesh* userData = (Mesh*)polygon_data;
userData->positionIndex.push_back((unsigned long)vertex_data);
userData->positionIndex.push_back(static_cast<unsigned long>(reinterpret_cast<size_t>(vertex_data)));
}
void CALLBACK tessEdgeFlag(GLboolean flag, void* polygon_data) {}

Expand All @@ -79,10 +79,10 @@ void CALLBACK tessCombineData(GLdouble newVert[3],
void** outData,
void* polygon_data) {
Mesh* userData = (Mesh*)polygon_data;
unsigned long index = static_cast<unsigned long>(userData->positions.size());
size_t index = userData->positions.size();
userData->positions.push_back(Vector3F(float(newVert[0]), float(newVert[1]), float(newVert[2])));
userData->normals.push_back(Vector3F(0.0f, 1.0f, 0.0f));
*outData = (void*)index;
*outData = reinterpret_cast<void*>(index);
};

const Mesh RVMMeshHelper2::makeBox(const Primitives::Box& inBox, const float& maxSideSize, const int& minSides) {
Expand Down Expand Up @@ -875,8 +875,8 @@ const Mesh RVMMeshHelper2::makeSphericalDish(const Primitives::SphericalDish& sD
return result;
}

pair<int, bool> createIndex(std::vector<Vertex>& references, const Vertex& newValue) {
unsigned int results = std::find(references.begin(), references.end(), newValue) - references.begin();
pair<size_t, bool> createIndex(std::vector<Vertex>& references, const Vertex& newValue) {
size_t results = std::find(references.begin(), references.end(), newValue) - references.begin();
if (results == references.size()) {
references.push_back(newValue);
return make_pair(results, true);
Expand All @@ -888,7 +888,7 @@ void RVMMeshHelper2::tesselateFacetGroup(const std::vector<std::vector<std::vect
Mesh* userData) {
GLUtesselator* tobj = gluNewTess();
vector<Vertex> indexedVertices;
vector<unsigned long> indexArray;
vector<size_t> indexArray;

gluTessCallback(tobj, GLU_TESS_EDGE_FLAG_DATA, (void(CALLBACK*)())tessEdgeFlag);
gluTessCallback(tobj, GLU_TESS_VERTEX_DATA, (void(CALLBACK*)())tessVertexData);
Expand All @@ -900,7 +900,7 @@ void RVMMeshHelper2::tesselateFacetGroup(const std::vector<std::vector<std::vect
for (unsigned int i = 0; i < vertices.size(); i++) {
for (unsigned int j = 0; j < vertices[i].size(); j++) {
for (unsigned int k = 0; k < vertices[i][j].size(); k++) {
pair<int, bool> res = createIndex(indexedVertices, vertices[i][j][k]);
pair<size_t, bool> res = createIndex(indexedVertices, vertices[i][j][k]);
indexArray.push_back(res.first);
if (res.second) {
userData->positions.push_back(vertices[i][j][k].first);
Expand All @@ -923,7 +923,7 @@ void RVMMeshHelper2::tesselateFacetGroup(const std::vector<std::vector<std::vect
coords[0] = vertex[0];
coords[1] = vertex[1];
coords[2] = vertex[2];
gluTessVertex(tobj, coords, (void*)indexArray[tessIndex]);
gluTessVertex(tobj, coords, reinterpret_cast<void*>(indexArray[tessIndex]));
tessIndex++;
}
gluTessEndContour(tobj);
Expand Down
33 changes: 18 additions & 15 deletions src/api/rvmmeshhelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
#include "vector3f.h"
#include "rvmprimitive.h"

#include "lib_export.h"

struct Mesh {
std::vector<unsigned long> positionIndex;
std::vector<unsigned long> normalIndex;
Expand All @@ -54,10 +56,11 @@ enum PrimitiveTypes {

typedef std::pair<Vector3F, Vector3F> Vertex;


class RVMMeshHelper2
{
public:
RVMMeshHelper2();
DLL_PMUC_EXPORT RVMMeshHelper2();

public:
/**
Expand All @@ -67,7 +70,7 @@ class RVMMeshHelper2
* @param minSides not used here. For consistency with the other methods.
* @return vertexes coordinates and their index.
*/
static const Mesh makePyramid(const Primitives::Pyramid& inP, const float& maxSideSize, const int& minSides);
DLL_PMUC_EXPORT static const Mesh makePyramid(const Primitives::Pyramid& inP, const float& maxSideSize, const int& minSides);

/**
* @brief Builds up indexed coordinates for the described box
Expand All @@ -78,7 +81,7 @@ class RVMMeshHelper2
* @param minSides not used here. For consistency with the other methods.
* @return vertexes coordinates and their index.
*/
static const Mesh makeBox(const Primitives::Box& box, const float& maxSideSize, const int& minSides);
DLL_PMUC_EXPORT static const Mesh makeBox(const Primitives::Box& box, const float& maxSideSize, const int& minSides);

/**
* @brief Builds up a sphere with the given radius
Expand All @@ -87,7 +90,7 @@ class RVMMeshHelper2
* @param minSides
* @return coordinates and normals with their indexes.
*/
static const Mesh makeSphere(const Primitives::Sphere &sphere, const float& maxSideSize, const int& minSides);
DLL_PMUC_EXPORT static const Mesh makeSphere(const Primitives::Sphere& sphere, const float& maxSideSize, const int& minSides);

/**
* @brief makeCylinder
Expand All @@ -97,7 +100,7 @@ class RVMMeshHelper2
*
* @return Returns a mesh object.
*/
static const Mesh makeCylinder(const Primitives::Cylinder &cylinder, unsigned long sides);
DLL_PMUC_EXPORT static const Mesh makeCylinder(const Primitives::Cylinder& cylinder, unsigned long sides);

/**
* @brief makeRectangularTorus
Expand All @@ -106,7 +109,7 @@ class RVMMeshHelper2
* @param minSides
* @return
*/
static const Mesh makeRectangularTorus(const Primitives::RectangularTorus& rt, const float& maxSideSize, const int& minSides);
DLL_PMUC_EXPORT static const Mesh makeRectangularTorus(const Primitives::RectangularTorus& rt, const float& maxSideSize, const int& minSides);

/**
* @brief makeCircularTorus
Expand All @@ -117,7 +120,7 @@ class RVMMeshHelper2
* @param minSides
* @return
*/
static const Mesh makeCircularTorus(const Primitives::CircularTorus& cTorus, unsigned long tsides, unsigned long csides);
DLL_PMUC_EXPORT static const Mesh makeCircularTorus(const Primitives::CircularTorus& cTorus, unsigned long tsides, unsigned long csides);

/**
* @brief makeSnout
Expand All @@ -130,7 +133,7 @@ class RVMMeshHelper2
* @param minSides
* @return
*/
static const Mesh makeSnout(const Primitives::Snout& snout, unsigned long sides);
DLL_PMUC_EXPORT static const Mesh makeSnout(const Primitives::Snout& snout, unsigned long sides);

/**
* @brief makeEllipticalDish
Expand All @@ -140,7 +143,7 @@ class RVMMeshHelper2
* @param csides
* @return
*/
static const Mesh makeEllipticalDish(const Primitives::EllipticalDish& eDish, unsigned long sides, unsigned long csides);
DLL_PMUC_EXPORT static const Mesh makeEllipticalDish(const Primitives::EllipticalDish& eDish, unsigned long sides, unsigned long csides);

/**
* @brief makeSphericalDish
Expand All @@ -150,10 +153,10 @@ class RVMMeshHelper2
* @param minSides
* @return
*/
static const Mesh makeSphericalDish(const Primitives::SphericalDish& sDish , const float& maxSideSize, const int& minSides);
DLL_PMUC_EXPORT static const Mesh makeSphericalDish(const Primitives::SphericalDish& sDish, const float& maxSideSize, const int& minSides);


static void tesselateFacetGroup(const std::vector<std::vector<std::vector<Vertex> > >& vertices, Mesh* meshData);
DLL_PMUC_EXPORT static void tesselateFacetGroup(const std::vector<std::vector<std::vector<Vertex> > >& vertices, Mesh* meshData);

/**
* @param cylinder The cylinder primitive data.
Expand All @@ -163,11 +166,11 @@ class RVMMeshHelper2
* @return Returns the number of sides of the cylinder.
*/

static unsigned long infoCylinderNumSides(const Primitives::Cylinder &cylinder, float maxSideSize, unsigned long minSides);
static unsigned long infoSnoutNumSides(const Primitives::Snout &snout, float maxSideSize, unsigned long minSides);
DLL_PMUC_EXPORT static unsigned long infoCylinderNumSides(const Primitives::Cylinder& cylinder, float maxSideSize, unsigned long minSides);
DLL_PMUC_EXPORT static unsigned long infoSnoutNumSides(const Primitives::Snout& snout, float maxSideSize, unsigned long minSides);

static std::pair<unsigned long, unsigned long> infoCircularTorusNumSides(const Primitives::CircularTorus& cTorus, float maxSideSize, unsigned long minSides);
static std::pair<unsigned long, unsigned long> infoEllipticalDishNumSides(const Primitives::EllipticalDish& eDish, float maxSideSize, unsigned long minSides);
DLL_PMUC_EXPORT static std::pair<unsigned long, unsigned long> infoCircularTorusNumSides(const Primitives::CircularTorus& cTorus, float maxSideSize, unsigned long minSides);
DLL_PMUC_EXPORT static std::pair<unsigned long, unsigned long> infoEllipticalDishNumSides(const Primitives::EllipticalDish& eDish, float maxSideSize, unsigned long minSides);
};

#endif // RVMMESHHELPER_H
Loading