Skip to content

Commit

Permalink
standalone converter (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
bareya authored Jun 23, 2017
1 parent f71a418 commit 039b476
Show file tree
Hide file tree
Showing 9 changed files with 319 additions and 168 deletions.
11 changes: 6 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ link_directories(${HOUDINI_LIBRARIES})

# MAYA
if(NOT DEFINED MAYA_DIR)
message(FATAL_ERROR "MAYA_DIR cmake variable is not set.")
message(FATAL_ERROR "MAYA_DIR cmake variable is not set.")
endif()
message(STATUS "Maya path:" ${MAYA_DIR})

Expand All @@ -28,13 +28,13 @@ set(BIFROST_DIR ${MAYA_DIR}/plug-ins/bifrost)

# BIFROST
if(NOT DEFINED BIFROST_DIR)
message(FATAL_ERROR "BIFROST_DIR cmake variable is not set.")
message(FATAL_ERROR "BIFROST_DIR cmake variable is not set.")
endif()
message(STATUS "Bifrost: " ${BIFROST_DIR})

# Bifrsot header test
if(NOT EXISTS ${BIFROST_DIR}/include/modules/aminomath/api/aminomath/mat.h)
message(FATAL_ERROR "mat.h not found")
message(FATAL_ERROR "mat.h not found")
endif()

# Add Bifrost dirs
Expand All @@ -45,11 +45,12 @@ execute_process(COMMAND ls ${BIFROST_DIR}/include/modules/ OUTPUT_VARIABLE BIFRO
string(REPLACE "\n" ";" BIFROST_MODULES ${BIFROST_MODULES})

foreach(module ${BIFROST_MODULES})
include_directories(${BIFROST_DIR}/include/modules/${module}/api/)
include_directories(${BIFROST_DIR}/include/modules/${module}/api/)
endforeach()

# RPath dirs
set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
SET(CMAKE_INSTALL_RPATH ${BIFROST_DIR}/lib)
set(CMAKE_INSTALL_RPATH ${BIFROST_DIR}/lib ${HOUDINI_DIR}/dsolib ${MAYA_DIR}/lib)

# Add src
add_subdirectory(src)
13 changes: 9 additions & 4 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
add_definitions(${HOUDINI_CXXFLAGS})

file(GLOB SOURCES "*.cpp")
file(GLOB HB_SOURCES "HoudiniBifrost.cpp" "GEO_BifrostIOTranslator.cpp" "newDSO.cpp")

add_library(${PROJECT_NAME} SHARED ${SOURCES})

target_link_libraries(${PROJECT_NAME} bifrostapi tbb HoudiniUT HoudiniGEO )
# libHoudiniBifrost
add_library(${PROJECT_NAME} SHARED ${HB_SOURCES})
target_link_libraries(${PROJECT_NAME} bifrostapi tbb HoudiniUT HoudiniGEO)
install(TARGETS ${PROJECT_NAME} DESTINATION ${HOME_HOUDINI_DSO})

# bif2geo
file(GLOB B2G_SOURCES "bif2geo.cpp")
add_executable("bif2geo" ${B2G_SOURCES})
target_link_libraries("bif2geo" HoudiniUT HoudiniGEO bifrostapi HoudiniBifrost)
install(TARGETS ${PROJECT_NAME} DESTINATION ${HOME_HOUDINI_DSO})
160 changes: 17 additions & 143 deletions src/GEO_BifrostIOTranslator.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#include "GEO_BifrostIOTranslator.h"

#include "GEO/GEO_Detail.h"
#include "GU/GU_Detail.h"
#include "UT/UT_IOTable.h"

#include "HoudiniBifrost.h"

#include <bifrostapi/bifrost_om.h>
#include <bifrostapi/bifrost_stateserver.h>
Expand All @@ -16,70 +19,6 @@
using namespace Bifrost::API;


struct ChannelAttributeAccessor
{
Channel m_channel;
GA_Attribute* m_attribute;
const GA_AIFTuple* m_tuple;
};


static ChannelAttributeAccessor createAttribute(GEO_Detail& geo, Ref& ch)
{
Channel channel(ch);
DataType type = channel.dataType();

if(channel.name()=="position" && type==FloatV3Type)
{
GA_Attribute* a = geo.getP();
return {ch, a, a->getAIFTuple()};
}

if(channel.name()=="velocity" && type==FloatV3Type)
{
GA_Attribute* a = geo.addFloatTuple(GA_ATTRIB_POINT,"v",3);
return {ch, a, a->getAIFTuple()};
}

if(channel.name()=="id64" && type==UInt64Type)
{
GA_Attribute* a = geo.addIntTuple(GA_ATTRIB_POINT, "id", 1);
return {ch, a, a->getAIFTuple()};
}

switch(type)
{
case UInt64Type:
case Int64Type:
{
GA_Attribute* a = geo.addIntTuple(GA_ATTRIB_POINT, channel.name().c_str(), 1);
return {ch, a, a->getAIFTuple()};
}
case FloatType:
{
GA_Attribute* a = geo.addFloatTuple(GA_ATTRIB_POINT, channel.name().c_str(), 1);
return {ch, a, a->getAIFTuple()};
}
case FloatV2Type:
{
GA_Attribute* a = geo.addFloatTuple(GA_ATTRIB_POINT, channel.name().c_str(), 2);
return {ch, a, a->getAIFTuple()};
}
case FloatV3Type:
{
GA_Attribute* a = geo.addFloatTuple(GA_ATTRIB_POINT, channel.name().c_str(), 3);
return {ch, a, a->getAIFTuple()};
}
default:
{
return {ch, nullptr, nullptr};
}
}

return {ch, nullptr, nullptr};
}


GEO_BifrostIOTranslator::GEO_BifrostIOTranslator()
: GEO_IOTranslator()
{
Expand Down Expand Up @@ -144,91 +83,26 @@ GA_Detail::IOStatus GEO_BifrostIOTranslator::fileLoad(GEO_Detail *gdp, UT_IStrea
return 0;
}

// component info
Layout layout = component.layout();
RefArray channels = component.channels();

// create attributes
std::vector<ChannelAttributeAccessor> channelAttributeMap;
for(int ch=0;ch<channels.count();++ch)
{
channelAttributeMap.emplace_back(createAttribute(*gdp, channels[ch]));
}

// create points
GA_Offset blockBegin = gdp->appendPointBlock(component.elementCount());
const GA_IndexMap& pointMap = gdp->getPointMap();

// tile iterator
for(size_t d=0; d<layout.depthCount(); ++d)
{
for(size_t t=0; t<layout.tileCount(d); ++t)
{
TreeIndex tindex(t,d);

size_t size{0};
for(auto it=channelAttributeMap.begin(); it!=channelAttributeMap.end(); ++it)
{
Channel& channel = (*it).m_channel;
DataType type = channel.dataType();

GA_Attribute* attrib = (*it).m_attribute;
const GA_AIFTuple* tuple = (*it).m_tuple;

// data pointer
const void* tileData = channel.tileDataPtr(tindex, size);
if(!tileData)
{
continue;
}

// point range
GA_Range range(pointMap, blockBegin, blockBegin+size);

switch(type)
{
case UInt64Type:
case Int64Type:
{
const int64* v = reinterpret_cast<const int64*>(tileData);
tuple->setRange(attrib, range, v, 0, 1);
break;
}
case FloatType:
{
const float* v = reinterpret_cast<const float*>(tileData);
tuple->setRange(attrib, range, v, 0, 1);
break;
}
case FloatV2Type:
{
const float* v = reinterpret_cast<const float*>(tileData);
tuple->setRange(attrib, range, v, 0, 2);
break;
}
case FloatV3Type:
{
const float* v = reinterpret_cast<const float*>(tileData);
tuple->setRange(attrib, range, v, 0, 3);
break;
}
default:
{
break;
}
}
}
blockBegin+=size;
}
}
convertBifrostPointCloud(component, *dynamic_cast<GU_Detail*>(gdp));

return 1;
}


GA_Detail::IOStatus GEO_BifrostIOTranslator::fileSave(const GEO_Detail *gdp, std::ostream &os)
GA_Detail::IOStatus GEO_BifrostIOTranslator::fileSave(const GEO_Detail*, std::ostream&)
{
std::cout << "Save option is not supported" << std::endl;
return 0;
}


void GEO_BifrostIOTranslator::install()
{
GU_Detail::registerIOTranslator(new GEO_BifrostIOTranslator());

UT_ExtensionList *geoextension = UTgetGeoExtensions();
if ( !geoextension->findExtension( "bif" ) )
{
geoextension->addExtension( "bif" );
}
}
6 changes: 6 additions & 0 deletions src/GEO_BifrostIOTranslator.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/

#ifndef GEO_BIFROSTIOTRANSLATOR_H
#define GEO_BIFROSTIOTRANSLATOR_H

#include "GEO/GEO_IOTranslator.h"

class GEO_BifrostIOTranslator : public GEO_IOTranslator
Expand All @@ -39,5 +42,8 @@ class GEO_BifrostIOTranslator : public GEO_IOTranslator

virtual GA_Detail::IOStatus fileLoad(GEO_Detail *gdp, UT_IStream &is, bool ate_magic);
virtual GA_Detail::IOStatus fileSave(const GEO_Detail *gdp, std::ostream &os);

static void install();
};

#endif//GEO_BIFROSTIOTRANSLATOR_H
Loading

0 comments on commit 039b476

Please sign in to comment.