Jump to content

DOP solver data issue


Recommended Posts

a header file:


//
//
//

#ifndef __my_solver_h__
#define __my_solver_h__

#include <UT/UT_DSOVersion.h>
#include <SIM/SIM_OptionsUser.h>
#include <SIM/SIM_Solver.h>


#define SIM_NAME_MY_PARM "myParm"


class SIM_MyOwnSolver : public SIM_Solver, public SIM_OptionsUser
{
public:

	GETSET_DATA_FUNCS_F(SIM_NAME_MY_PARM, myParm);

protected:
	explicit SIM_MyOwnSolver(const SIM_DataFactory *factory);
    	virtual ~SIM_MyOwnSolver();

	// This implements your own solver step
	virtual SIM_Solver::SIM_Result solveObjectsSubclass(
		SIM_Engine &engine,
		SIM_ObjectArray &objects,
		SIM_ObjectArray &newobjects,
		SIM_ObjectArray &feedbacktoobjects,
		const SIM_Time &timestep);

private:
	static const SIM_DopDescription* getMyOwnSolverDescription();

	DECLARE_STANDARD_GETCASTTOTYPE();
	DECLARE_DATAFACTORY(SIM_MyOwnSolver,
			SIM_Solver, 
			"SIM_MyOwnSolver",
			getMyOwnSolverDescription());
	};

#endif

cpp file:

//my solver

#include "my_solver.h"

#include <UT/UT_DSOVersion.h>
#include <UT/UT_XformOrder.h>
#include <PRM/PRM_Include.h>
#include <SIM/SIM_DopDescription.h>
#include <SIM/SIM_DataFilter.h>
#include <SIM/SIM_Object.h>
#include <SIM/SIM_SDF.h>
#include <SIM/SIM_ObjectArray.h>
#include <SIM/SIM_OptionsUser.h>
#include <SIM/SIM_Options.h>
#include <SIM/SIM_Data.h>
#include <SIM/SIM_Query.h>
#include <RBD/RBD_State.h>
#include <SIM/SIM_Engine.h>
#include <SIM/SIM_Force.h>
#include <SIM/SIM_ForcePoint.h>
#include <SIM/SIM_ForceUniform.h>
#include <SIM/SIM_ForceGravity.h>
#include <SIM/SIM_Constraint.h>
#include <SIM/SIM_ConAnchorObjSpacePos.h>
#include <SIM/SIM_ConAnchorWorldSpacePos.h>
#include <SIM/SIM_ConAnchor.h>
#include <SIM/SIM_ConRel.h>
#include <SIMZ/SIM_PopGeometry.h>
#include <GEO/GEO_Detail.h>
#include <UT/UT_Quaternion.h>






//Constructor
SIM_MyOwnSolver::SIM_MyOwnSolver(const SIM_DataFactory *factory)
: BaseClass(factory),
SIM_OptionsUser(this)
{

}

//Destructor
SIM_MyOwnSolver::~SIM_MyOwnSolver()
{

}


const SIM_DopDescription * SIM_MyOwnSolver::getMyOwnSolverDescription()
{

	static PRM_Name	 themyParm(SIM_NAME_MY_PARM, "myParm");
	static PRM_Default defmyParm(155.55f);

	static PRM_Template	theTemplates[] = {
			PRM_Template(PRM_FLT_J,	1,  &themyParm,  &defmyParm),
			PRM_Template()
	};

	static SIM_DopDescription   theDopDescription(true,
		"SIM_MyOwnSolver",
		"SIM_MyOwnSolver",
		"Solver",
		classname(),
		theTemplates);

	return &theDopDescription;
}



SIM_Solver::SIM_Result SIM_MyOwnSolver::solveObjectsSubclass(
			SIM_Engine &engine,
			SIM_ObjectArray &objects,
			SIM_ObjectArray &newobjects,
			SIM_ObjectArray &feedbacktoobjects,
			const SIM_Time &timestep)
{

        //it can be even 
        //float aaa=getmyParm();

	int i;
	int totalDopObjects = engine.getNumSimulationObjects();

	for(i = 0; i < totalDopObjects; i++)
	{
		//Get current dop sim object
		SIM_Object *currObject = (SIM_Object *)engine.getSimulationObject(i);

		SIM_MyOwnSolver *state = SIM_DATA_GET(*currObject, "Solver", SIM_MyOwnSolver);

		float aaa=state->getmyParm();
		float bbb=currObject->getObjectId();

		cout<< "myParm: " << aaa /*<< "; time: " << currTime*/ <<endl;		
		cout<< "ObjectId: " << bbb /*<< "; time: " << currTime*/ <<endl;




	}

	cout <<endl;


	return SIM_SOLVER_SUCCESS;
};



void initializeSIM(void *)
{
	IMPLEMENT_DATAFACTORY(SIM_MyOwnSolver);
}


this simple solver with one parameter do cast this parameter to DOP property and print eval of this property to stdout

Edited by almatea
Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...