Skip to content

Commit

Permalink
ISSUE #391 General clean up for code review: #402
Browse files Browse the repository at this point in the history
  • Loading branch information
haroon-haider committed Dec 11, 2020
1 parent 6f5db15 commit 29117f0
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -141,18 +141,17 @@ void RepoModelImport::parseMaterial(const boost::property_tree::ptree &matTree)
{
textureIdToParents[textureId].push_back(materialNode->getSharedID());
}
return;
}

void RepoModelImport::parseTexture(
const boost::property_tree::ptree& textureTree,
char * const dataBuffer)
{
bool fileNameOk = textureTree.find("filename") != textureTree.not_found();
bool byteCountOK = textureTree.find("numImageBytes") != textureTree.not_found();
bool widthOk = textureTree.find("width") != textureTree.not_found();
bool heightOk = textureTree.find("height") != textureTree.not_found();
bool idOk = textureTree.find("id") != 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();

if (!byteCountOK ||
!widthOk ||
Expand All @@ -164,13 +163,13 @@ void RepoModelImport::parseTexture(
return;
}

std::string name = fileNameOk ? textureTree.get_child("filename").data() : "";
uint32_t byteCount = textureTree.get<uint32_t>("numImageBytes");
uint32_t width = textureTree.get<uint32_t>("width");
uint32_t height = textureTree.get<uint32_t>("height");
uint32_t id = textureTree.get<uint32_t>("id");
std::string name = fileNameOk ? textureTree.get_child(REPO_TXTR_FNAME).data() : "";
uint32_t byteCount = textureTree.get<uint32_t>(REPO_TXTR_NUM_BYTES);
uint32_t width = textureTree.get<uint32_t>(REPO_TXTR_WIDTH);
uint32_t height = textureTree.get<uint32_t>(REPO_TXTR_HEIGHT);
uint32_t id = textureTree.get<uint32_t>(REPO_TXTR_ID);

std::vector<uint32_t> DataStartEnd = as_vector<uint32_t>(textureTree, "imageBytes");
std::vector<uint64_t> DataStartEnd = as_vector<uint64_t>(textureTree, REPO_TXTR_IMG_BYTES);

char* data = &dataBuffer[DataStartEnd[0]];

Expand All @@ -182,18 +181,14 @@ void RepoModelImport::parseTexture(
byteCount,
width,
height,
REPO_NODE_API_LEVEL_1));
REPO_NODE_API_LEVEL_1,
&textureIdToParents[id]));

repo::core::model::TextureNode* tmpTexture = new repo::core::model::TextureNode();
*tmpTexture = textureNode->cloneAndAddParent(textureIdToParents[id]);
textures.insert(tmpTexture);

return;
textures.insert(textureNode);
}


RepoModelImport::mesh_data_t RepoModelImport::createMeshRecord(
int parentBimId,
const ptree &mesh,
const std::string &parentName,
const repo::lib::RepoUUID &parentID,
Expand Down Expand Up @@ -236,8 +231,7 @@ RepoModelImport::mesh_data_t RepoModelImport::createMeshRecord(
{
materialID = props->second.get_value<int>();
}

if (props->first == REPO_IMPORT_VERTICES || props->first == REPO_IMPORT_NORMALS)
else if (props->first == REPO_IMPORT_VERTICES || props->first == REPO_IMPORT_NORMALS)
{
std::vector<int64_t> startEnd = as_vector<int64_t>(mesh, props->first);

Expand Down Expand Up @@ -275,8 +269,7 @@ RepoModelImport::mesh_data_t RepoModelImport::createMeshRecord(
}
}
}

if (props->first == REPO_IMPORT_UV)
else if (props->first == REPO_IMPORT_UV)
{
std::vector<int64_t> startEnd = as_vector<int64_t>(mesh, props->first);
float* tmpUVs = (float*)(dataBuffer + startEnd[0]);
Expand All @@ -288,8 +281,7 @@ RepoModelImport::mesh_data_t RepoModelImport::createMeshRecord(
}
uvChannels.push_back(uvChannelVector);
}

if (props->first == REPO_IMPORT_INDICES)
else if (props->first == REPO_IMPORT_INDICES)
{
std::vector<int64_t> startEnd = as_vector<int64_t>(mesh, REPO_IMPORT_INDICES);

Expand Down Expand Up @@ -326,7 +318,7 @@ RepoModelImport::mesh_data_t RepoModelImport::createMeshRecord(
matParents[materialID].push_back(sharedID);
}

mesh_data_t result = { parentBimId, vertices, normals, uvChannels, faces, boundingBox, parentID, sharedID };
mesh_data_t result = { vertices, normals, uvChannels, faces, boundingBox, parentID, sharedID };
return result;
}

Expand Down Expand Up @@ -379,7 +371,7 @@ void RepoModelImport::createObject(const ptree& tree)

if (props->first == REPO_IMPORT_GEOMETRY)
{
auto mesh = createMeshRecord(myID, props->second, transName, transID, trans_matrix_map.back());
auto mesh = createMeshRecord(props->second, transName, transID, trans_matrix_map.back());
metaParentIDs.push_back(mesh.sharedID);
meshEntries.push_back(mesh);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,24 @@ namespace repo {
const char REPO_IMPORT_TYPE_BOOL = 'B';
const char REPO_IMPORT_TYPE_DATETIME = 'T';

const std::string REPO_IMPORT_METADATA = "metadata";
const std::string REPO_IMPORT_GEOMETRY = "geometry";
const std::string REPO_IMPORT_MATERIAL = "material";
const std::string REPO_IMPORT_VERTICES = "vertices";
const std::string REPO_IMPORT_UV = "uv";
const std::string REPO_IMPORT_NORMALS = "normals";
const std::string REPO_IMPORT_INDICES = "indices";
// Node JSON fields
const std::string REPO_IMPORT_METADATA = "metadata";
const std::string REPO_IMPORT_GEOMETRY = "geometry";
const std::string REPO_IMPORT_MATERIAL = "material";
const std::string REPO_IMPORT_VERTICES = "vertices";
const std::string REPO_IMPORT_UV = "uv";
const std::string REPO_IMPORT_NORMALS = "normals";
const std::string REPO_IMPORT_INDICES = "indices";
const std::string REPO_IMPORT_BBOX = "bbox";

// Texture JSON fields
const std::string REPO_TXTR_FNAME = "filename";
const std::string REPO_TXTR_NUM_BYTES = "numImageBytes";
const std::string REPO_TXTR_WIDTH = "width";
const std::string REPO_TXTR_HEIGHT = "height";
const std::string REPO_TXTR_ID = "id";
const std::string REPO_TXTR_IMG_BYTES = "imageBytes";

const std::string REPO_IMPORT_BBOX = "bbox";

const static int REPO_VERSION_LENGTH = 6;

Expand Down Expand Up @@ -88,7 +97,6 @@ namespace repo {

struct mesh_data_t
{
int parentBimId;
std::vector<repo::lib::RepoVector3D64> rawVertices;
std::vector<repo::lib::RepoVector3D> normals;
std::vector<std::vector<repo::lib::RepoVector2D>> uvChannels;
Expand All @@ -101,7 +109,7 @@ namespace repo {
void parseMaterial(const boost::property_tree::ptree& pt);
void parseTexture(const boost::property_tree::ptree& textureTree, char * dataBuffer);
repo::core::model::MetadataNode* createMetadataNode(const boost::property_tree::ptree &metadata, const std::string &parentName, const repo::lib::RepoUUID &parentID);
mesh_data_t createMeshRecord(int parentBimId, const boost::property_tree::ptree &geometry, const std::string &parentName, const repo::lib::RepoUUID &parentID, const repo::lib::RepoMatrix &trans);
mesh_data_t createMeshRecord(const boost::property_tree::ptree &geometry, const std::string &parentName, const repo::lib::RepoUUID &parentID, const repo::lib::RepoMatrix &trans);

/**
* @brief Creates a property tree from the current
Expand Down
4 changes: 2 additions & 2 deletions test/src/system/st_3drepobouncerClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,12 @@ static int testUpload (
std::string fileName
)
{
std::string bimUpload = produceUploadArgs(
std::string uploadCmd = produceUploadArgs(
mongoDbName,
projectName,
getDataPath(fileName));

int errCode = runProcess(bimUpload);
int errCode = runProcess(uploadCmd);
;
repoInfo << "Error code from bouncer client: " << errCode
<< ", " << (int)errCode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "../../../../repo_test_utils.h"
#include "../../../../repo_test_database_info.h"
#include "boost/filesystem.hpp"
#include "../../bouncer/src/repo/error_codes.h"

using namespace repo::manipulator::modelconvertor;

Expand Down
2 changes: 0 additions & 2 deletions test/src/unit/repo_test_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
#include "repo_test_database_info.h"
#include "repo_test_fileservice_info.h"
#include <fstream>
#include <repo/lib/repo_log.h>
#include "../../bouncer/src/repo/error_codes.h"

static repo::RepoController::RepoToken* initController(repo::RepoController *controller) {
repo::lib::RepoConfig config = { REPO_GTEST_DBADDRESS, REPO_GTEST_DBPORT,
Expand Down

0 comments on commit 29117f0

Please sign in to comment.