Search the Community
Showing results for tags 'inlinecpp'.
-
Hi I cannot figure out how to pass an array of vector3 (or array of quaternions or matrices) to my inlinecpp. I know there is something like "geo.setPointFloatAttribValuesFromString("P", positions)" but i dont have Points yet in my Operator. I do know how to pass a single Vector or an Array of Integers. If anyone has an example on how to do this, thank you this one is using numpy and is not working: import inlinecpp import numpy as np import ctypes Cpp_lib = inlinecpp.createLibrary("Arrayexample", includes=""" #include <hboost\iostreams\detail\iostream.hpp> #include <SYS/SYS_Types.h> #include <UT/UT_Vector3.h> #include <UT/UT_Storage.h> """, function_sources=[""" void vecArray(UT_Vector3D * vec, int l) { for(int i=0; i < l ; ++i) std::cout << (*vec)[i] << std::endl; } """]) v0 = hou.Vector3(0.5, 0.2, 0.3) v1 = hou.Vector3(1.5, 2.2, 3.3) v2 = hou.Vector3(2.5, 3.2, 4.4) myVectorArray = np.array([v0, v1, v2]) Cpp_lib.vecArray( myVectorArray.ctypes.data , len(myVectorArray)) this is working: import inlinecpp cpp_lib = inlinecpp.createLibrary("example", includes=""" #include <hboost\iostreams\detail\iostream.hpp> #include <SYS/SYS_Types.h> #include <UT/UT_Vector3.h> #include <UT/UT_Storage.h> """, function_sources=[""" void saysomething2(UT_Vector3D * vec) { for(int i=0; i < 3 ; ++i) std::cout << (*vec)[i] << std::endl; } """]) v = hou.Vector3(0.5, 0.2, 0.3) cpp_lib.saysomething2(v) this one is using the array module and is working, but how could I define a custom type (hou.Vector3) in the array module? import array import inlinecpp example_lib = inlinecpp.createLibrary("example_lib", function_sources=[""" inlinecpp::BinaryString build_int_array() { std::vector<int> values(10); for (int i=0; i<10; ++i) values[i] = i; return inlinecpp::as_binary_string(values); } """]) data = example_lib.build_int_array() int_array = array.array("i", data) for value in int_array: print value
-
import inlinecpp inlinecpp.extendClass(hou.Geometry, "geo_merge_HOM_ext", "", [""" void mergePrimGroup(GU_Detail* gdp, const GU_Detail* src, const char* prim_grp) { gdp->merge(*src, src->findPrimitiveGroup(prim_grp)); } """]) "AttributeError: function ?mergePrimGroupy...yadadada not found" This error only occurs when "src" is const, or gdp isn't const. Basically if the const-ness of the GU_Detail args are mismatched the function "can't be found". Does anyone know anything about this? Thanks
-
Hi there I am building a pc2 writer sop to export point cache data from Houdini I have a working python solution but it can be a bit slow (code has been hacked from the various examples on odforce ect) see below: import sys, struct def doCache(): sf = hou.evalParm("startframe") ef = hou.evalParm("endframe") sr = 1 ns = (ef - sf) + 1 geo = hou.pwd().geometry() points = geo.points() np = len(points) pc2File = open(hou.evalParm("file"), "wb") geo = hou.pwd().geometry() # Write header headerFormat='<12siiffi' headerStr = struct.pack(headerFormat, "POINTCACHE2\0", 1, np, sf, sr, ns) pc2File.write(headerStr) # iterate points def writePP(p,f): hou.setFrame(f) curp = p.position() curps = pc2File.write( struct.pack('<fff', float(curp[0]), float(-curp[2]), float(curp[1]) ) ) a = [ writePP(p,f) for f in xrange(sf, sf+ns, sr) for p in geo.points() ] # close file pc2File.flush() pc2File.close() Due to slow speeds I am attempting to implement this using inlinecpp to speed up the execution time. My attempt can be found below, (non-functional at the mo). I am a HDK newb so there are probably lots of very simple mistakes in there. Would anyone with HDK experience be able to give me a few pointers in where I am going wrong? import sys import struct import inlinecpp writePts = inlinecpp.createLibrary( name="cpp_string_library", includes="#include <GU/GU_Detail.h>, #include <FS/FS_Writer.h>, #include <UT/UT_Vector3.h>, #include <HOM/HOM_Module.h>", function_sources=[ """void writePC2(GU_Detail *gdp, const char *filename, const char *pc2, int *numPoints, float *start, float *samplerate, int *numSamples ) { // open the file for writing FS_Writer fs(filename); ostream *file = fs.getStream(); // write header file << pc2; file << int(1); file << numPoints; file << start; file << samplerate; file << numSamples; // iterate through frames through points for ( float i=start; i<end; ++i) { HOM_Module::setFrame( double(i) ) //iterate through the points GA_Offset ptoff; GA_FOR_ALL_PTOFF(gdp, ptoff) { UT_Vector3 pos = gdp->getPos3(ptoff); file << pos.x << pos.y << pos.z; } } // close the file file.close() } """]) def doCache(): sf = hou.evalParm("startframe") ef = hou.evalParm("endframe") sr = 1 ns = (ef - sf) + 1 geo = hou.pwd().geometry() filename = hou.evalParm("file") pc2 = "POINTCACHE2\0" writePts.writePC2(geo, filename, pc2, len(geo.points), sf, sr, ns) Much obliged!!! Sam Swift-Glasman