Skip to content

Commit

Permalink
Improving specifications of volume and support in afFramework
Browse files Browse the repository at this point in the history
  • Loading branch information
adnanmunawar committed Jul 10, 2021
1 parent e309466 commit cca46aa
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 34 deletions.
7 changes: 7 additions & 0 deletions adf_loader/version_1_0/adf_loader_1_0.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2205,13 +2205,20 @@ bool ADFLoader_1_0::loadVolumeAttribs(YAML::Node *a_node, afVolumeAttributes *at
YAML::Node nameNode = node["name"];
YAML::Node nameSpaceNode = node["namespace"];
YAML::Node imagesNode = node["images"];
YAML::Node dimensionsNode = node["dimensions"];


ADFUtils::getIdentificationAttribsFromNode(&node, &attribs->m_identificationAttribs);
ADFUtils::getKinematicAttribsFromNode(&node, &attribs->m_kinematicAttribs);
ADFUtils::getHierarchyAttribsFromNode(&node, &attribs->m_hierarchyAttribs);
ADFUtils::getCommunicationAttribsFromNode(&node, &attribs->m_communicationAttribs);
ADFUtils::getShaderAttribsFromNode(&node, &attribs->m_shaderAttribs);
ADFUtils::getPluginAttribsFromNode(&node, &attribs->m_pluginAttribs);

if (dimensionsNode.IsDefined()){
attribs->m_dimensions = ADFUtils::positionFromNode(&dimensionsNode);
}

if (imagesNode.IsDefined()){
YAML::Node pathNode = imagesNode["path"];
YAML::Node prefixNode = imagesNode["prefix"];
Expand Down
10 changes: 7 additions & 3 deletions ambf_framework/afAttributes.h
Original file line number Diff line number Diff line change
Expand Up @@ -909,9 +909,9 @@ enum class afVolumeSpecificationType{
///
/// \brief The afMultiImagesAttribs struct
///
struct afMultiImagesAttribs{
struct afMultiImagesAttributes{
public:
afMultiImagesAttribs(){
afMultiImagesAttributes(){
m_count = 0;
}
afPath m_path;
Expand All @@ -930,11 +930,15 @@ struct afMultiImagesAttribs{
struct afVolumeAttributes: public afBaseObjectAttributes{
public:
afVolumeAttributes(){
m_dimensions.set(1.0, 1.0, 1.0);
}

afKinematicAttributes m_kinematicAttribs;
afHierarchyAttributes m_hierarchyAttribs;
afVolumeSpecificationType m_specificationType;
afMultiImagesAttribs m_multiImageAttribs;
afMultiImagesAttributes m_multiImageAttribs;
afShaderAttributes m_shaderAttribs;
afVector3d m_dimensions;

virtual void resolveRelativePathAttribs(afPath a_parentPath){
m_shaderAttribs.m_vtxFilepath.resolvePath(a_parentPath);
Expand Down
99 changes: 74 additions & 25 deletions ambf_framework/afFramework.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5499,6 +5499,18 @@ afGhostObjectPtr afObjectManager::getGhostObject(btGhostObject *a_body, bool sup
return ghostObj;
}


///
/// \brief afObjectManager::getVolume
/// \param a_name
/// \param suppress_warning
/// \return
///
afVolumePtr afObjectManager::getVolume(string a_name, bool suppress_warning)
{
return (afVolumePtr)getBaseObject(a_name, getVolumeMap(), suppress_warning);
}

///
/// \brief afObjectManager::getVehicle
/// \param a_name
Expand Down Expand Up @@ -5633,6 +5645,20 @@ string afObjectManager::addVehicle(afVehiclePtr a_obj){
return remaped_identifier;
}

///
/// \brief afObjectManager::addVolume
/// \param a_volume
/// \return
///
string afObjectManager::addVolume(afVolumePtr a_obj)
{
string qualified_identifier = a_obj->getQualifiedIdentifier();
string remap_str = afUtils::getNonCollidingIdx(qualified_identifier, getVehicleMap());
string remaped_identifier = qualified_identifier + remap_str;
addBaseObject(a_obj, qualified_identifier + remap_str);
return remaped_identifier;
}

string afObjectManager::addBaseObject(afBaseObjectPtr a_obj)
{
string remaped_name = "";
Expand All @@ -5649,6 +5675,9 @@ string afObjectManager::addBaseObject(afBaseObjectPtr a_obj)
case afType::VEHICLE:
remaped_name = addVehicle((afVehiclePtr)a_obj);
break;
case afType::VOLUME:
remaped_name = addVolume((afVolumePtr)a_obj);
break;
case afType::GHOST_OBJECT:
remaped_name = addGhostObject((afGhostObjectPtr)a_obj);
break;
Expand Down Expand Up @@ -5746,6 +5775,16 @@ afVehicleVec afObjectManager::getVehicles(){
}


///
/// \brief afObjectManager::getVolumes
/// \return
///
afVolumeVec afObjectManager::getVolumes()
{
return getBaseObjects<afVolume>(getVolumeMap());
}


///
/// \brief afModelManager::getModel
/// \param a_name
Expand Down Expand Up @@ -8543,7 +8582,7 @@ bool afModel::createFromAttribs(afModelAttributes *a_attribs)
for (size_t i = 0; i < attribs.m_volumeAttribs.size(); ++i) {
afVolumePtr volumePtr = new afVolume(m_afWorld, this);
if (volumePtr->createFromAttribs(&attribs.m_volumeAttribs[i])){
// addLight(lightPtr);
addVolume(volumePtr);
}
}

Expand Down Expand Up @@ -9424,60 +9463,70 @@ afVolume::~afVolume()
bool afVolume::createFromAttribs(afVolumeAttributes *a_attribs)
{
m_attribs = *a_attribs;
afVolumeAttributes &attribs = *a_attribs;

setNamespace(attribs.m_identificationAttribs.m_namespace);
setName(attribs.m_identificationAttribs.m_name);
setIdentifier(attribs.m_identifier);

setLocalTransform(attribs.m_kinematicAttribs.m_location);
m_scale = attribs.m_kinematicAttribs.m_scale;

if (m_attribs.m_specificationType == afVolumeSpecificationType::MULTI_IMAGE){
m_multiImage = cMultiImage::create();
string path_and_prefix = m_attribs.m_multiImageAttribs.m_path.c_str() + "/" + m_attribs.m_multiImageAttribs.m_prefix;
if (m_multiImage->loadFromFiles(path_and_prefix, m_attribs.m_multiImageAttribs.m_format, m_attribs.m_multiImageAttribs.m_count)){

m_voxelObject = new cVoxelObject();
// Setting transparency before setting the texture ensures that the rendering does not show empty spaces as black
// and the depth point cloud is able to see the volume
m_voxelObject->setTransparencyLevel(1.0);

cTexture3dPtr texture = cTexture3d::create();
texture->setImage(m_multiImage);
m_voxelObject = new cVoxelObject();
m_voxelObject->setTexture(texture);

cShaderProgramPtr shaderPgm = afShaderUtils::createFromAttribs(&m_attribs.m_shaderAttribs, m_name, "VOLUME");
if (shaderPgm){
m_voxelObject->setCustomShaderProgram(shaderPgm);
}
else{
m_voxelObject->setRenderingModeIsosurfaceColorMap();
}

m_voxelObject->setLocalPos(0.0, 0.0, 0.0);

// rotate object
m_voxelObject->rotateExtrinsicEulerAnglesDeg(90, 30, -90, C_EULER_ORDER_YXZ);

// set the dimensions by assigning the position of the min and max corners
m_voxelObject->m_minCorner.set(-0.5,-0.5,-0.5);
m_voxelObject->m_maxCorner.set( 0.5, 0.5, 0.5);
m_voxelObject->m_minCorner << ( attribs.m_dimensions / -2.0) * m_scale;
m_voxelObject->m_maxCorner << ( attribs.m_dimensions / 2.0) * m_scale;

// set the texture coordinate at each corner.
m_voxelObject->m_minTextureCoord.set(0.0, 0.0, 0.0);
m_voxelObject->m_maxTextureCoord.set(1.0, 1.0, 1.0);

// set haptic properties
m_voxelObject->m_material->setStiffness(0.2 * 1);
m_voxelObject->m_material->setStaticFriction(0.0);
m_voxelObject->m_material->setDynamicFriction(0.0);
// // set haptic properties
// m_voxelObject->m_material->setStiffness(0.2 * 1);
// m_voxelObject->m_material->setStaticFriction(0.0);
// m_voxelObject->m_material->setDynamicFriction(0.0);

// enable materials
m_voxelObject->setUseMaterial(true);
// // enable materials
// m_voxelObject->setUseMaterial(true);

// set material
m_voxelObject->m_material->setWhite();
// // set material
// m_voxelObject->m_material->setWhite();

// set quality of graphic rendering
m_voxelObject->setQuality(0.5);

m_voxelObject->setTransparencyLevel(1.0);

m_voxelObject->setIsosurfaceValue(0.45);
m_voxelObject->setOpticalDensity(1.2);

m_afWorld->addSceneObjectToWorld(m_voxelObject);
addChildSceneObject(m_voxelObject, cTransform());

cShaderProgramPtr shaderPgm = afShaderUtils::createFromAttribs(&m_attribs.m_shaderAttribs, m_name, "VOLUME");
if (shaderPgm){
m_voxelObject->setCustomShaderProgram(shaderPgm);
}
else{
m_voxelObject->setRenderingModeIsosurfaceColors();
}
}
else{
cerr << "ERROR! FAILED TO LOAD VOLUME FROM MULTI_IMAGES PATH: " << m_attribs.m_multiImageAttribs.m_path.c_str() << "/" << m_attribs.m_multiImageAttribs.m_prefix << endl;
return false;
}
}

Expand Down
24 changes: 18 additions & 6 deletions ambf_framework/afFramework.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ class afRigidBody;
class afSoftBody;
class afGhostObject;
class afJoint;
class afVolume;
class afWorld;
struct afRenderOptions;
class afCartesianController;
Expand All @@ -141,7 +140,6 @@ typedef afWorld* afWorldPtr;
typedef afConstraintActuator* afConstraintActuatorPtr;
typedef afRayTracerSensor* afRayTracerSensorPtr;
typedef afResistanceSensor* afResistanceSensorPtr;
typedef afVolume* afVolumePtr;

typedef map<string, afRigidBodyPtr> afRigidBodyMap;
typedef map<string, afSoftBodyPtr> afSoftBodyMap;
Expand All @@ -152,15 +150,16 @@ typedef vector<afSoftBodyPtr> afSoftBodyVec;
typedef vector<afGhostObjectPtr> afGhostObjectVec;
typedef vector<afJointPtr> afJointVec;
//------------------------------------------------------------------------------
class afLight;
class afCamera;
typedef afLight* afLightPtr;
typedef afCamera* afCameraPtr;
typedef map<string, afLightPtr> afLightMap;
typedef map<string, afCameraPtr> afCameraMap;
typedef vector<afLightPtr> afLightVec;
typedef vector<afCameraPtr> afCameraVec;
//------------------------------------------------------------------------------
class afLight;
typedef afLight* afLightPtr;
typedef map<string, afLightPtr> afLightMap;
typedef vector<afLightPtr> afLightVec;
//------------------------------------------------------------------------------
class afSensor;
class afResistanceSensor;
typedef afSensor* afSensorPtr;
Expand All @@ -182,6 +181,11 @@ typedef afVehicle* afVehiclePtr;
typedef map<string, afVehiclePtr> afVehicleMap;
typedef vector<afVehiclePtr> afVehicleVec;
//------------------------------------------------------------------------------
class afVolume;
typedef afVolume* afVolumePtr;
typedef map<string, afVolumePtr> afVolumeMap;
typedef vector<afVolumePtr> afVolumeVec;
//------------------------------------------------------------------------------
class afPointCloud;
typedef afPointCloud* afPointCloudPtr;
typedef cMultiPoint* cMultiPointPtr;
Expand Down Expand Up @@ -750,6 +754,8 @@ class afObjectManager{

string addVehicle(afVehiclePtr a_vehicle);

string addVolume(afVolumePtr a_volume);

string addBaseObject(afBaseObjectPtr a_obj);

bool addBaseObject(afBaseObjectPtr a_obj, string a_name);
Expand Down Expand Up @@ -788,6 +794,8 @@ class afObjectManager{

afVehiclePtr getVehicle(string a_name, bool suppress_warning=false);

afVolumePtr getVolume(string a_name, bool suppress_warning=false);

afBaseObjectPtr getBaseObject(string a_name, afBaseObjectMap* a_map, bool suppress_warning);

// Template method to get all objects of specific type
Expand All @@ -813,6 +821,8 @@ class afObjectManager{

afVehicleVec getVehicles();

afVolumeVec getVolumes();


inline afBaseObjectMap* getLightMap(){return &m_childrenObjectsMap[afType::LIGHT];}

Expand All @@ -832,6 +842,8 @@ class afObjectManager{

inline afBaseObjectMap* getVehicleMap(){return &m_childrenObjectsMap[afType::VEHICLE];}

inline afBaseObjectMap* getVolumeMap(){return &m_childrenObjectsMap[afType::VOLUME];}

inline afChildrenMap* getChildrenMap(){return &m_childrenObjectsMap;}

// Return true if object exists in the vec
Expand Down

0 comments on commit cca46aa

Please sign in to comment.