Tamis Posted June 28, 2008 Share Posted June 28, 2008 (edited) Hey hey, I have been doing some more exploration of the HDK and figured out how to implement volumes So this is the first thing i would like to share with any one who is interested in them. Parameters static PRM_Name PrmNames[]= { PRM_Name("iter","iterations"), PRM_Name("pos","position"), //PRM_Name("fvfv","sa"), }; PRM_Template SDF::MyTemplatelist[] = { PRM_Template(PRM_INT_XYZ_J,3,&PrmNames[0]), PRM_Template(PRM_XYZ_J,3,&PrmNames[1]), //PRM_Template(PRM_XYZ_J,3,&PrmNames[2]), }; Function to get voxol world space position UT_Vector3 getWorldSpace(GU_PrimVolume *voxPrim,UT_VoxelArray <fpreal> *vox,int tileX,int tileY,int tileZ) { /*Get Tile position in Voxol Space [0-1]*/ UT_Vector3 pos; vox->indexToPos(tileX,tileY,tileZ,pos); /*GetBoudningBox*/ UT_BoundingBox bounds; voxPrim->getBBox(&bounds); /*Calculate to world space*/ float localX = (((bounds.xsize()/vox->getRes(0))*tileX)+bounds.xmin()); float localY = (((bounds.ysize()/vox->getRes(1))*tileY)+bounds.ymin()); float localZ = (((bounds.zsize()/vox->getRes(2))*tileZ)+bounds.zmin()); /*RETURN*/ pos.x() = localX; pos.y() = localY; pos.z() = localZ; return pos; }; Cook method /*INITIALISE Parameters*/ int Volume_Iterations_X_Parameter = evalInt(0,0,context.myTime); int Volume_Iterations_Y_Parameter = evalInt(0,1,context.myTime); int Volume_Iterations_Z_Parameter = evalInt(0,2,context.myTime); float Volume_Position_X_Parameter = evalInt(1,0,context.myTime); float Volume_Position_Y_Parameter = evalInt(1,1,context.myTime); float Volume_Position_Z_Parameter = evalInt(1,2,context.myTime); // float Volume_Position_Sphere_X_Parameter = evalInt(2,0,context.myTime); // float Volume_Position_Sphere_Y_Parameter = evalInt(2,1,context.myTime); // float Volume_Position_Sphere_Z_Parameter = evalInt(2,2,context.myTime); float Volume_Radius_Parameter = 1;//evalFloat(2,0,context.myTime); if (lockInputs(context) >= UT_ERROR_ABORT) return error(); // duplicateSource(0,context,gdp,1); gdp->clearAndDestroy(); /*Get Bounds*/ const UT_Matrix4 boundMat; UT_BoundingBox bound; inputGeo(0,context)->getBBox(bound,boundMat); /*GU_PrimVolume is a PRIMITIVE type so it just as if it is a polygone or face in houdini*/ /*It creates a container that holds voxel data*/ GU_PrimVolume *volume_Container = (GU_PrimVolume*)GU_PrimVolume::build(gdp); /*Turn it into a SDF*/ volume_Container->isSDF(); /*Move voxel array to point out that the voxolo sphere is based on world positions*/ UT_Matrix4 *transf; volume_Container->getTransform4(*transf); UT_Vector3 transl; transl.x() = Volume_Position_X_Parameter; transl.y() = Volume_Position_Y_Parameter; transl.z() = Volume_Position_Z_Parameter; transf->setTranslates(transl); volume_Container->setTransform4(*transf); /*UT_VoxelArray is a template class wich means it can take in difrent types of data like float int UT_Vector or in this case fpreal*/ UT_VoxelArray <fpreal> *voxols = new UT_VoxelArray <fpreal>; voxols->size(Volume_Iterations_X_Parameter,Volume_Iterations_Y_Parameter,Volume_Iterations_Z_Parameter); /*Lets do a loop thrue the volume*/ for(int X=0; X<Volume_Iterations_X_Parameter;X++) for(int Y=0; Y<Volume_Iterations_Y_Parameter;Y++) for(int Z=0; Z<Volume_Iterations_Z_Parameter;Z++) { // UT_Vector3 pos; // voxols->indexToPos(X,Y,Z,pos); if(getWorldSpace(volume_Container,voxols,X,Y,Z).length() < Volume_Radius_Parameter) voxols->setValue(X,Y,Z,(fpreal)1); } /*Here i dump the voxols into the container and then build the geometry detail pointer this means it will insert itself in a compteble format into the gdp*/ /*DISCO TIME*/ volume_Container->setVoxels(voxols); // volume_Container->build(gdp); unlockInputs(); return error(); Now the question i want to ask is do you guys experience a lot of segmentation errors when it comes to parameters? In my code i just posted you can see i commented out a parameter and when i uncomment this then Houdini will give me a segmentation error. Sometimes having a comma at the end in my parameter definition fixes this problem and sometimes not putting down a comma fixes it aswel. Is any one experiencing the same thing or am i working with a somewhat bugged version of houdini? I'm running on Ubuntu Hardy. Edited June 28, 2008 by Tamis Quote Link to comment Share on other sites More sharing options...
edward Posted June 28, 2008 Share Posted June 28, 2008 Offhand, it looks like you're missing a PRM_Template() to terminate your parm list. So something like this: PRM_Template SDF::MyTemplatelist[] = { PRM_Template(PRM_INT_XYZ_J,3,&PrmNames[0]), PRM_Template(PRM_XYZ_J,3,&PrmNames[1]), //PRM_Template(PRM_XYZ_J,3,&PrmNames[2]), PRM_Template() // sentinel }; Quote Link to comment Share on other sites More sharing options...
Tamis Posted June 29, 2008 Author Share Posted June 29, 2008 (edited) ah i didn't know that was needed! thnx for the help edit: One question if you don't mind.... I'm trying to scale the volume container to the bounding size of the object in the 1st input. Now this is what i have right now, i know the primitive group is not a necessity but it was just a test, i tried it without as well. UT_BoundingBox *bound; GU_Detail GEO = *inputGeo(0); GB_PrimitiveGroup *Pgrp = GEO.newPrimitiveGroup("blabla",1); for(int i = 0; i <= GEO.primitives().entries(); i++) Pgrp->add(GEO.primitives()[i]); GEO.getBBox(bound,Pgrp); Now the problem is is that in Houdini i get incorrect value's back.(The bounding box center is 0,0,0) 1.03641e+34 4.2039e-45 Now the objects bounding box center is 1,1,1 1 1.03641e+34 4.2039e-45 the last 2 numbers always remain the same i print the value's as followed: std::cout << bound->centerX() << std::endl; std::cout << bound->centerY() << std::endl; std::cout << bound->centerZ() << std::endl; Personally i think the method is just f**** up but it might be that i am doing something wrong. Edited June 29, 2008 by Tamis Quote Link to comment Share on other sites More sharing options...
Tamis Posted June 29, 2008 Author Share Posted June 29, 2008 Aaah never mind i got it. I uprated to 9.5 and in 9.5 it gives a segmentation error on that code. what i did was: UT_BoundingBox *bound; ->getBBox(bound); And it is suppost to be: UT_BoundingBox bound; ->getBBox(&bound); Hoduini 9.0 just gave me funky numbers back 9.5 actually crashes on it Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.