Skip to content

Commit

Permalink
ISSUE #391 fix compilation on ODA, change function call to not pass i…
Browse files Browse the repository at this point in the history
…n default paramters
  • Loading branch information
carmenfan committed Dec 14, 2020
1 parent 490c113 commit 6ec0e11
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 75 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/


#include "geometry_collector.h"

#include <assimp/scene.h>
Expand All @@ -25,10 +24,8 @@ using namespace repo::manipulator::modelconvertor::odaHelper;

GeometryCollector::GeometryCollector()
{

}


GeometryCollector::~GeometryCollector()
{
}
Expand Down Expand Up @@ -64,12 +61,11 @@ repo::core::model::TransformationNode GeometryCollector::createRootNode()
}

void GeometryCollector::setCurrentMaterial(const repo_material_t &material, bool missingTexture) {

auto checkSum = material.checksum();
if(idxToMat.find(checkSum) == idxToMat.end()) {
idxToMat[checkSum] = {
repo::core::model::RepoBSONFactory::makeMaterialNode(material),
createTextureNode(material.texturePath)
if (idxToMat.find(checkSum) == idxToMat.end()) {
idxToMat[checkSum] = {
repo::core::model::RepoBSONFactory::makeMaterialNode(material),
createTextureNode(material.texturePath)
};

if (missingTexture)
Expand All @@ -91,11 +87,9 @@ mesh_data_t GeometryCollector::createMeshEntry() {
entry.layerName = nextLayer.empty() ? "UnknownLayer" : nextLayer;

return entry;

}

void GeometryCollector::startMeshEntry() {

nextMeshName = nextMeshName.empty() ? std::to_string(std::time(0)) : nextMeshName;
nextGroupName = nextGroupName.empty() ? nextMeshName : nextGroupName;
nextLayer = nextLayer.empty() ? nextMeshName : nextLayer;
Expand All @@ -112,19 +106,18 @@ void GeometryCollector::startMeshEntry() {
meshData[nextGroupName][nextLayer][currMat] = createMeshEntry();
}
currentEntry = &meshData[nextGroupName][nextLayer][currMat];

}

void GeometryCollector::stopMeshEntry() {
if(currentEntry)
currentEntry->vToVIndex.clear();
if (currentEntry)
currentEntry->vToVIndex.clear();
nextMeshName = "";
}

void GeometryCollector::addFace(
const std::vector<repo::lib::RepoVector3D64> &vertices,
const std::vector<repo::lib::RepoVector3D64> &vertices,
const repo::lib::RepoVector3D64& normal,
const std::vector<repo::lib::RepoVector2D>& uvCoords)
const std::vector<repo::lib::RepoVector2D>& uvCoords)
{
if (!meshData.size()) startMeshEntry();

Expand All @@ -140,7 +133,7 @@ void GeometryCollector::addFace(
}

if (faceHasUV && uvCoords.size() != vertices.size()) {
repoError << "Vertices size["<< vertices.size() << "] and UV size ["<< uvCoords.size() <<"] mismatched!";
repoError << "Vertices size[" << vertices.size() << "] and UV size [" << uvCoords.size() << "] mismatched!";
exit(-1);
}

Expand All @@ -151,9 +144,9 @@ void GeometryCollector::addFace(
if (currentEntry->vToVIndex.find(v) == currentEntry->vToVIndex.end()) {
//..insert new vertex along with index and normal
currentEntry->vToVIndex.insert(
std::pair<repo::lib::RepoVector3D64,
std::pair<repo::lib::RepoVector3D64,
std::pair<int, repo::lib::RepoVector3D64>>(
v,
v,
std::pair<int, repo::lib::RepoVector3D64>(currentEntry->rawVertices.size(), normal))
);
vertIdx = currentEntry->rawVertices.size();
Expand All @@ -163,13 +156,13 @@ void GeometryCollector::addFace(
currentEntry->uvCoords.push_back(uvCoords[i]);

if (currentEntry->boundingBox.size()) {
currentEntry->boundingBox[0][0] = currentEntry->boundingBox[0][0] > v.x ? (float) v.x : currentEntry->boundingBox[0][0];
currentEntry->boundingBox[0][1] = currentEntry->boundingBox[0][1] > v.y ? (float) v.y : currentEntry->boundingBox[0][1];
currentEntry->boundingBox[0][2] = currentEntry->boundingBox[0][2] > v.z ? (float) v.z : currentEntry->boundingBox[0][2];
currentEntry->boundingBox[0][0] = currentEntry->boundingBox[0][0] > v.x ? (float)v.x : currentEntry->boundingBox[0][0];
currentEntry->boundingBox[0][1] = currentEntry->boundingBox[0][1] > v.y ? (float)v.y : currentEntry->boundingBox[0][1];
currentEntry->boundingBox[0][2] = currentEntry->boundingBox[0][2] > v.z ? (float)v.z : currentEntry->boundingBox[0][2];

currentEntry->boundingBox[1][0] = currentEntry->boundingBox[1][0] < v.x ? (float) v.x : currentEntry->boundingBox[1][0];
currentEntry->boundingBox[1][1] = currentEntry->boundingBox[1][1] < v.y ? (float) v.y : currentEntry->boundingBox[1][1];
currentEntry->boundingBox[1][2] = currentEntry->boundingBox[1][2] < v.z ? (float) v.z : currentEntry->boundingBox[1][2];
currentEntry->boundingBox[1][0] = currentEntry->boundingBox[1][0] < v.x ? (float)v.x : currentEntry->boundingBox[1][0];
currentEntry->boundingBox[1][1] = currentEntry->boundingBox[1][1] < v.y ? (float)v.y : currentEntry->boundingBox[1][1];
currentEntry->boundingBox[1][2] = currentEntry->boundingBox[1][2] < v.z ? (float)v.z : currentEntry->boundingBox[1][2];
}
else {
currentEntry->boundingBox.push_back({ (float)v.x, (float)v.y, (float)v.z });
Expand Down Expand Up @@ -205,7 +198,7 @@ void GeometryCollector::addFace(

if (!normalFound)
{
//.. in case the normal for this point doesn't exist yet - we should add it
//.. in case the normal for this point doesn't exist yet - we should add it
//.. as duplicated and add new normal and index
currentEntry->vToVIndex.insert(
std::pair<repo::lib::RepoVector3D64,
Expand All @@ -228,7 +221,6 @@ void GeometryCollector::addFace(
currentEntry->faces.push_back(face);
}


repo::core::model::RepoNodeSet GeometryCollector::getMeshNodes(const repo::core::model::TransformationNode& root) {
repo::core::model::RepoNodeSet res;
auto dummyCol = std::vector<repo_color4d_t>();
Expand All @@ -242,13 +234,12 @@ repo::core::model::RepoNodeSet GeometryCollector::getMeshNodes(const repo::core:
for (const auto &meshMatEntry : meshLayerEntry.second) {
if (!meshMatEntry.second.rawVertices.size()) continue;

auto uvChannels = meshMatEntry.second.uvCoords.size() ?
auto uvChannels = meshMatEntry.second.uvCoords.size() ?
std::vector<std::vector<repo::lib::RepoVector2D>>{meshMatEntry.second.uvCoords} :
std::vector<std::vector<repo::lib::RepoVector2D>>();


if (layerToTrans.find(meshLayerEntry.first) == layerToTrans.end()) {
layerToTrans[meshLayerEntry.first] = createTransNode(layerIDToName[meshLayerEntry.first], meshLayerEntry.first, rootId);
layerToTrans[meshLayerEntry.first] = createTransNode(layerIDToName[meshLayerEntry.first], meshLayerEntry.first, rootId);
transNodes.insert(layerToTrans[meshLayerEntry.first]);
}

Expand Down Expand Up @@ -279,7 +270,6 @@ repo::core::model::RepoNodeSet GeometryCollector::getMeshNodes(const repo::core:
{ layerToTrans[meshLayerEntry.first]->getSharedID() }
);


if (idToMeta.find(meshGroupEntry.first) != idToMeta.end()) {
metaNodes.insert(createMetaNode(meshGroupEntry.first, { meshNode.getSharedID() }, idToMeta[meshGroupEntry.first]));
}
Expand All @@ -303,14 +293,14 @@ repo::core::model::MetadataNode* GeometryCollector::createMetaNode(
const repo::lib::RepoUUID &parentId,
const std::unordered_map<std::string, std::string> &metaValues
) {
return new repo::core::model::MetadataNode(repo::core::model::RepoBSONFactory::makeMetaDataNode(metaValues, name, {parentId}));
return new repo::core::model::MetadataNode(repo::core::model::RepoBSONFactory::makeMetaDataNode(metaValues, name, { parentId }));
}

repo::core::model::TransformationNode* GeometryCollector::createTransNode(
const std::string &name,
const std::string &id,
const repo::lib::RepoUUID &parentId)
{
const repo::lib::RepoUUID &parentId)
{
auto transNode = new repo::core::model::TransformationNode(repo::core::model::RepoBSONFactory::makeTransformationNode(repo::lib::RepoMatrix(), name, { parentId }));
if (idToMeta.find(id) != idToMeta.end()) {
metaNodes.insert(createMetaNode(name, transNode->getSharedID(), idToMeta[id]));
Expand All @@ -329,7 +319,6 @@ bool GeometryCollector::hasMissingTextures()
}

void GeometryCollector::getMaterialAndTextureNodes(repo::core::model::RepoNodeSet& materials, repo::core::model::RepoNodeSet& textures) {

materials.clear();
textures.clear();

Expand Down Expand Up @@ -373,8 +362,7 @@ repo::core::model::TextureNode GeometryCollector::createTextureNode(const std::s
(const char*)memblock,
size,
1,
0,
REPO_NODE_API_LEVEL_1
0
);

delete[] memblock;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ RepoModelImport::~RepoModelImport()
}

repo::core::model::MetadataNode* RepoModelImport::createMetadataNode(
const ptree &metaTree,
const std::string &parentName,
const ptree &metaTree,
const std::string &parentName,
const repo::lib::RepoUUID &parentID)
{
std::vector<std::string> keys, values;
Expand Down Expand Up @@ -137,25 +137,25 @@ void RepoModelImport::parseMaterial(const boost::property_tree::ptree &matTree)
materials.insert(materialNode);
matNodeList.push_back(materialNode);

if(textureId >= 0)
if (textureId >= 0)
{
textureIdToParents[textureId].push_back(materialNode->getSharedID());
}
}

void RepoModelImport::parseTexture(
const boost::property_tree::ptree& textureTree,
const boost::property_tree::ptree& textureTree,
char * const dataBuffer)
{
bool fileNameOk = textureTree.find(REPO_TXTR_FNAME) != textureTree.not_found();
bool fileNameOk = textureTree.find(REPO_TXTR_FNAME) != textureTree.not_found();
bool byteCountOK = textureTree.find(REPO_TXTR_NUM_BYTES) != textureTree.not_found();
bool widthOk = textureTree.find(REPO_TXTR_WIDTH) != textureTree.not_found();
bool heightOk = textureTree.find(REPO_TXTR_HEIGHT) != textureTree.not_found();
bool idOk = textureTree.find(REPO_TXTR_ID) != textureTree.not_found();
bool widthOk = textureTree.find(REPO_TXTR_WIDTH) != textureTree.not_found();
bool heightOk = textureTree.find(REPO_TXTR_HEIGHT) != textureTree.not_found();
bool idOk = textureTree.find(REPO_TXTR_ID) != textureTree.not_found();

if (!byteCountOK ||
!widthOk ||
!heightOk ||
!widthOk ||
!heightOk ||
!idOk)
{
repoError << "Required texture field missing. Skipping this texture.";
Expand All @@ -181,13 +181,11 @@ void RepoModelImport::parseTexture(
byteCount,
width,
height,
textureIdToParents[id],
REPO_NODE_API_LEVEL_1));

textureIdToParents[id]));

textures.insert(textureNode);
}


RepoModelImport::mesh_data_t RepoModelImport::createMeshRecord(
const ptree &mesh,
const std::string &parentName,
Expand Down Expand Up @@ -276,7 +274,7 @@ RepoModelImport::mesh_data_t RepoModelImport::createMeshRecord(
std::vector<repo::lib::RepoVector2D> uvChannelVector;
for (int i = 0; i < numVertices; i++)
{
repo::lib::RepoVector2D tmpUVVec = repo::lib::RepoVector2D(tmpUVs[i * 2] , tmpUVs[i * 2 + 1]);
repo::lib::RepoVector2D tmpUVVec = repo::lib::RepoVector2D(tmpUVs[i * 2], tmpUVs[i * 2 + 1]);
uvChannelVector.push_back(tmpUVVec);
}
uvChannels.push_back(uvChannelVector);
Expand Down Expand Up @@ -434,24 +432,24 @@ bool RepoModelImport::importModel(std::string filePath, uint8_t &err)
repoInfo << "Loading BIM file [VERSION: " << incomingVersion << "]";

size_t metaSize = REPO_VERSION_LENGTH + sizeof(fileMeta);
if(incomingVersion == REPO_V3)
if (incomingVersion == REPO_V3)
{
fin->read((char*)&file_meta, REPO_V3_FILEMETA_BYTE_LEN);
}
else
{
fin->read((char*)&file_meta, REPO_V2_FILEMETA_BYTE_LEN);
}
repoInfo << std::left << std::setw(30) << "File meta size: " << metaSize;
repoInfo << std::left << std::setw(30) << "JSON size: " << file_meta.jsonSize << " bytes";
repoInfo << std::left << std::setw(30) << "Data buffer size: " << file_meta.dataSize << " bytes";
repoInfo << std::left << std::setw(30) << "\"sizes\" array start location: "<< file_meta.sizesStart << " bytes";
repoInfo << std::left << std::setw(30) << "\"sizes\" array size: " << file_meta.sizesSize << " bytes";
repoInfo << std::left << std::setw(30) << "\"materials\" array location: " << file_meta.matStart << " bytes";
repoInfo << std::left << std::setw(30) << "\"materials\" array size: " << file_meta.matSize << " bytes";
repoInfo << std::left << std::setw(30) << "\"textures\" array location: " << file_meta.textureSize << " bytes";
repoInfo << std::left << std::setw(30) << "\"textures\" array size: " << file_meta.textureStart << " bytes";
repoInfo << std::left << std::setw(30) << "Number of parts to process:" << file_meta.numChildren;
repoInfo << std::left << std::setw(30) << "File meta size: " << metaSize;
repoInfo << std::left << std::setw(30) << "JSON size: " << file_meta.jsonSize << " bytes";
repoInfo << std::left << std::setw(30) << "Data buffer size: " << file_meta.dataSize << " bytes";
repoInfo << std::left << std::setw(30) << "\"sizes\" array start location: " << file_meta.sizesStart << " bytes";
repoInfo << std::left << std::setw(30) << "\"sizes\" array size: " << file_meta.sizesSize << " bytes";
repoInfo << std::left << std::setw(30) << "\"materials\" array location: " << file_meta.matStart << " bytes";
repoInfo << std::left << std::setw(30) << "\"materials\" array size: " << file_meta.matSize << " bytes";
repoInfo << std::left << std::setw(30) << "\"textures\" array location: " << file_meta.textureSize << " bytes";
repoInfo << std::left << std::setw(30) << "\"textures\" array size: " << file_meta.textureStart << " bytes";
repoInfo << std::left << std::setw(30) << "Number of parts to process:" << file_meta.numChildren;

// Load full JSON tree
boost::property_tree::ptree jsonRoot = getNextJSON(file_meta.jsonSize);
Expand Down Expand Up @@ -479,7 +477,7 @@ bool RepoModelImport::importModel(std::string filePath, uint8_t &err)
return false;
}
boost::optional<ptree&> sizesRoot = jsonRoot.get_child_optional("sizes");
if(sizesRoot)
if (sizesRoot)
{
sizes = as_vector<long>(sizesRoot.get());
}
Expand All @@ -499,9 +497,9 @@ bool RepoModelImport::importModel(std::string filePath, uint8_t &err)
repoInfo << "Loaded: " << textures.size() << " textures";
int maxTextureId = textureIdToParents.rbegin()->first;
if (maxTextureId > (textures.size() - 1))
{
{
repoError << "A material is referencing a missing texture";
missingTextures = true;
missingTextures = true;
}
}

Expand Down Expand Up @@ -572,7 +570,7 @@ repo::core::model::RepoScene* RepoModelImport::generateRepoScene(uint8_t &errMsg
trans_matrix_map.push_back(transMat);
transformations.insert(rootNode);

// Process children of root node
// Process children of root node
char comma;
for (long i = 0; i < file_meta.numChildren; i++)
{
Expand Down Expand Up @@ -608,7 +606,7 @@ repo::core::model::RepoScene* RepoModelImport::generateRepoScene(uint8_t &errMsg
for (const auto &entry : meshEntries) {
std::vector<repo::lib::RepoVector3D> vertices;
std::vector<std::vector<float>> boundingBox;
// Offsetting all the verts by the world offset to reduce the magnitude
// Offsetting all the verts by the world offset to reduce the magnitude
// of their values so they can be cast to floats (widely used in 3D libs)
for (const auto &v : entry.rawVertices) {
repo::lib::RepoVector3D v32 = { (float)(v.x - offset[0]), (float)(v.y - offset[1]), (float)(v.z - offset[2]) };
Expand Down Expand Up @@ -640,10 +638,10 @@ repo::core::model::RepoScene* RepoModelImport::generateRepoScene(uint8_t &errMsg
// Generate scene
repo::core::model::RepoScene * scenePtr = new repo::core::model::RepoScene(fileVect, cameras, meshes, materials, metadata, textures, transformations);
scenePtr->setWorldOffset(offset);
if (missingTextures)
if (missingTextures)
{
errMsg = REPOERR_LOAD_SCENE_MISSING_TEXTURE;
scenePtr->setMissingTexture();
scenePtr->setMissingTexture();
}

// Cleanup
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -826,9 +826,7 @@ repo::core::model::RepoScene* AssimpModelImport::convertAiSceneToRepoScene()
(char*)texture->pcData,
size,
texture->mWidth,
texture->mHeight,
std::vector<repo::lib::RepoUUID>(),
REPO_NODE_API_LEVEL_1));
texture->mHeight));

free(memblock);
}
Expand Down Expand Up @@ -860,9 +858,7 @@ repo::core::model::RepoScene* AssimpModelImport::convertAiSceneToRepoScene()
memblock,
size,
size,
0,
std::vector<repo::lib::RepoUUID>(),
REPO_NODE_API_LEVEL_1));
0));

if (memblock)delete[] memblock;
}
Expand Down

0 comments on commit 6ec0e11

Please sign in to comment.