- fixed particle generation bug tracked down by mpan3&gimble,

- removed warnings in attributes.cpp,
- and a first Klockwork bug fix: removed NULL returns in ntl_ray.h,
  several other issues mentioned in the Klockwork report
  are either hard to fix or not really errors...
This commit is contained in:
Nils Thuerey 2006-11-29 19:28:07 +00:00
parent 8c6fe1bb1f
commit f1b74d0098
12 changed files with 94 additions and 71 deletions

@ -18,9 +18,11 @@
*****************************************************************************/
bool Attribute::initChannel(int elemSize) {
elemSize=0; // remove warning
return false;
}
string Attribute::getAsString(bool debug) {
debug=false; // remove warning
return string("");
}
int Attribute::getAsInt() {
@ -36,6 +38,7 @@ ntlVec3d Attribute::getAsVec3d() {
return ntlVec3d(0.);
}
void Attribute::getAsMat4Gfx(ntlMat4Gfx *mat) {
mat=NULL; // remove warning
}
string Attribute::getCompleteString() {
return string("");
@ -73,22 +76,29 @@ void AttributeList::setAllUsed() {
* Attribute list read functions
*****************************************************************************/
int AttributeList::readInt(string name, int defaultValue, string source,string target, bool needed) {
name=source=target=string(""); needed=false; // remove warning
return defaultValue;
}
bool AttributeList::readBool(string name, bool defaultValue, string source,string target, bool needed) {
name=source=target=string(""); needed=false; // remove warning
return defaultValue;
}
double AttributeList::readFloat(string name, double defaultValue, string source,string target, bool needed) {
name=source=target=string(""); needed=false; // remove warning
return defaultValue;
}
string AttributeList::readString(string name, string defaultValue, string source,string target, bool needed) {
name=source=target=string(""); needed=false; // remove warning
return defaultValue;
}
ntlVec3d AttributeList::readVec3d(string name, ntlVec3d defaultValue, string source,string target, bool needed) {
name=source=target=string(""); needed=false; // remove warning
return defaultValue;
}
void AttributeList::readMat4Gfx(string name, ntlMat4Gfx defaultValue, string source,string target, bool needed, ntlMat4Gfx *mat) {
*mat = defaultValue;
name=source=target=string(""); needed=false; mat=NULL; // remove warning
}
// set that a parameter can be given, and will be ignored...
@ -98,21 +108,27 @@ bool AttributeList::ignoreParameter(string name, string source) {
// read channels
AnimChannel<int> AttributeList::readChannelInt(string name, int defaultValue, string source, string target, bool needed) {
name=source=target=string(""); needed=false; // remove warning
return AnimChannel<int>(defaultValue);
}
AnimChannel<double> AttributeList::readChannelFloat(string name, double defaultValue, string source, string target, bool needed ) {
name=source=target=string(""); needed=false; // remove warning
return AnimChannel<double>(defaultValue);
}
AnimChannel<ntlVec3d> AttributeList::readChannelVec3d(string name, ntlVec3d defaultValue, string source, string target, bool needed ) {
name=source=target=string(""); needed=false; // remove warning
return AnimChannel<ntlVec3d>(defaultValue);
}
AnimChannel<ntlSetVec3f> AttributeList::readChannelSetVec3f(string name, ntlSetVec3f defaultValue, string source, string target, bool needed) {
name=source=target=string(""); needed=false; // remove warning
return AnimChannel<ntlSetVec3f>(defaultValue);
}
AnimChannel<float> AttributeList::readChannelSinglePrecFloat(string name, float defaultValue, string source, string target, bool needed ) {
name=source=target=string(""); needed=false; // remove warning
return AnimChannel<float>(defaultValue);
}
AnimChannel<ntlVec3f> AttributeList::readChannelVec3f(string name, ntlVec3f defaultValue, string source, string target, bool needed) {
name=source=target=string(""); needed=false; // remove warning
return AnimChannel<ntlVec3f>(defaultValue);
}
@ -140,6 +156,7 @@ void AttributeList::print() {
* import attributes from other attribute list
*****************************************************************************/
void AttributeList::import(AttributeList *oal) {
oal=NULL; // remove warning
}

@ -131,13 +131,15 @@ class ntlSetVec3f {
class Attribute
{
public:
Attribute(string mn, vector<string> &value, int setline,bool channel) { };
Attribute(Attribute &a) { };
Attribute(string mn, vector<string> &value, int setline,bool channel) {
mn = string(""); setline=0; channel=false; value.clear(); // remove warnings
};
Attribute(Attribute &a) { a.getCompleteString(); };
~Attribute() { };
void setUsed(bool set){ }
void setUsed(bool set){ set=false; }
bool getUsed() { return true; }
void setIsChannel(bool set){ }
void setIsChannel(bool set){ set=false; }
bool getIsChannel() { return false; }
string getAsString(bool debug=false);
@ -166,10 +168,12 @@ class Attribute
class AttributeList
{
public:
AttributeList(string name) { };
AttributeList(string name) { name=string(""); };
~AttributeList();
void addAttr(string name, vector<string> &value, int line, bool isChannel) { }
bool exists(string name) { return false; }
void addAttr(string name, vector<string> &value, int line, bool isChannel) {
name=string(""); value.clear(); line=0; isChannel=false; // remove warnings
};
bool exists(string name) { name=string(""); return false; }
void setAllUsed();
bool checkUnusedParams();
void import(AttributeList *oal);

@ -217,6 +217,7 @@ ntlTree::ntlTree(int depth, int objnum, ntlScene *scene, int triFlagMask) :
}
}
mppTriangles->push_back( &(*iter) );
//errMsg("TreeDebug","Triangle "<<(*mpVertices)[(*iter).getPoints()[0]]<<" "<<(*mpVertices)[(*iter).getPoints()[1]]<<" "<<(*mpVertices)[(*iter).getPoints()[2]]<<" ");
// add BB
mpTBB[ bbCount ].start = bbs;
@ -296,7 +297,7 @@ ntlTree::~ntlTree()
*****************************************************************************/
void ntlTree::subdivide(BSPNode *node, int depth, int axis)
{
int nextAxis; /* next axis to partition */
int nextAxis=0; /* next axis to partition */
int allTriDistSet = (1<<0)|(1<<1); // all mpTriDist flags set?
//errorOut(" "<<node<<" depth:"<<depth<<" m:"<<node->members->size() <<" "<<node->min<<" - "<<node->max );

@ -121,7 +121,7 @@ ntlColor ntlLightObject::illuminatePoint(ntlRay &reflectedRay, ntlGeometryObject
// where is the lightsource ?
ntlRay rayOfLight(intersectionPos, lightDir, 0, 1.0, mpGlob );
if( (mCastShadows)&&(closest->getReceiveShadows()) ) {
if( (1) && (mCastShadows)&&(closest->getReceiveShadows()) ) {
ntlTriangle *tri;
ntlVec3Gfx triNormal;
gfxReal trit;
@ -131,6 +131,7 @@ ntlColor ntlLightObject::illuminatePoint(ntlRay &reflectedRay, ntlGeometryObject
}
/* is light partly visible ? */
//? visibility=1.;
if (visibility>0.0) {
ntlColor highTemp(0.0); // temporary highlight color to multiply highTemp with offFac
current_color = getShadedColor(reflectedRay, lightDir, clossurf, highTemp) * visibility;
@ -149,10 +150,8 @@ ntlMaterial::ntlMaterial( void ) :
mName( "default" ),
mDiffuseRefl(0.5,0.5,0.5), mAmbientRefl(0.0,0.0,0.0),
mSpecular(0.0), mSpecExponent(0.0), mMirror(0.0),
mTransparence(0.0), mRefracIndex(0.0), mTransAdditive(0.0), mTransAttCol(0.0),
mFresnel( 0 )
//mNtfId(0), mNtfFluid(0), mNtfSolid(0)
{
mTransparence(0.0), mRefracIndex(1.05), mTransAdditive(0.0), mTransAttCol(0.0),
mFresnel( 0 ) {
// just do default init...
}

@ -594,22 +594,19 @@ const ntlColor ntlRay::shade() //const
/* Trace another ray on for transparent objects */
if(currTrans > RAY_THRESHOLD) {
//gfxReal refrac_dn = mDirection | normal;
/* position at the other side of the surface, along ray */
ntlVec3Gfx refraction_position(mOrigin + (mDirection * minT) );
refraction_position += (mDirection * getVecEpsilon());
refraction_position -= (triangleNormal*getVecEpsilon() );
ntlColor refracCol(0.0); /* refracted color */
/* trace refracted ray */
ntlRay transRay(refraction_position, refractedDir, mDepth+1, mContribution*currTrans, mpGlob);
transRay.setRefracted(1);
transRay.setNormal( normal );
if(mDepth < mpGlob->getRayMaxDepth() ) {
if(!refRefl) {
// full reflection should make sure refracindex&fresnel are on...
if((0)||(!refRefl)) {
if(mpGlob->getDebugOut() > 5) errorOut("Refracted ray from depth "<<mDepth<<", dir "<<refractedDir );
refracCol = transRay.shade();
} else {
@ -618,17 +615,19 @@ const ntlColor ntlRay::shade() //const
refracCol = reflectedRay.shade();
}
}
//errMsg("REFMIR","t"<<currTrans<<" thres"<<RAY_THRESHOLD<<" mirr"<<currRefl<<" refRefl"<<refRefl<<" md"<<mDepth);
/* calculate color */
// use transadditive setting!?
/* additive transparency "light amplification" */
ntlColor add_col = currentColor + refracCol * currTrans;
/* subtractive transparency, more realistic */
ntlColor sub_col = (refracCol * currTrans) +
( currentColor * (1.0-currTrans) );
//? ntlColor add_col = currentColor + refracCol * currTrans;
/* mix additive and subtractive */
add_col += sub_col;
currentColor += (refracCol * currTrans);
//? add_col += sub_col;
//? currentColor += (refracCol * currTrans);
/* subtractive transparency, more realistic */
ntlColor sub_col = (refracCol * currTrans) + ( currentColor * (1.0-currTrans) );
currentColor = sub_col;
}
@ -873,8 +872,13 @@ void ntlScene::prepareScene(double time)
buildScene(time, false);
// what for currently not used ???
if(mpTree != NULL) delete mpTree;
mpTree = new ntlTree( mpGlob->getTreeMaxDepth(), mpGlob->getTreeMaxTriangles(),
this, TRI_GEOMETRY );
mpTree = new ntlTree(
# if FSGR_STRICT_DEBUG!=1
mpGlob->getTreeMaxDepth(), mpGlob->getTreeMaxTriangles(),
# else
mpGlob->getTreeMaxDepth()/3*2, mpGlob->getTreeMaxTriangles()*2,
# endif
this, TRI_GEOMETRY );
//debMsgStd("ntlScene::prepareScene",DM_MSG,"Stats - tris:"<< (int)mTriangles.size()<<" verts:"<<mVertices.size()<<" vnorms:"<<mVertNormals.size(), 5 );
}

@ -336,17 +336,17 @@ public:
/*! Acces a certain object */
inline ntlGeometryObject *getObject(int id) {
if(!mSceneBuilt) { errMsg("ntlScene::getObject","Scene not inited!"); return NULL; }
if(!mSceneBuilt) { errFatal("ntlScene::getObject","Scene not inited!", SIMWORLD_INITERROR); }
return mObjects[id]; }
/*! Acces object array */
inline vector<ntlGeometryObject*> *getObjects() {
if(!mSceneBuilt) { errMsg("ntlScene::getObjects[]","Scene not inited!"); return NULL; }
if(!mSceneBuilt) { errFatal("ntlScene::getObjects[]","Scene not inited!", SIMWORLD_INITERROR); }
return &mObjects; }
/*! Acces geo class array */
inline vector<ntlGeometryClass*> *getGeoClasses() {
if(!mSceneBuilt) { errMsg("ntlScene::getGeoClasses[]","Scene not inited!"); return NULL; }
if(!mSceneBuilt) { errFatal("ntlScene::getGeoClasses[]","Scene not inited!", SIMWORLD_INITERROR); }
return &mGeos; }
/*! draw scene with opengl */

@ -61,7 +61,7 @@ ntlWorld::ntlWorld(string filename, bool commandlineMode)
finishWorldInit();
#else // ELBEEM_PLUGIN
errFatal("ntlWorld::init","Cfg file parsing not supported for API version!", SIMWORLD_INITERROR);
errFatal("ntlWorld::init","Cfg file parsing not supported for API version! "<<filename<<" "<<commandlineMode, SIMWORLD_INITERROR);
#endif // ELBEEM_PLUGIN
}
@ -257,11 +257,6 @@ void ntlWorld::setSingleFrameOut(string singleframeFilename) {
* render a whole animation (command line mode)
*****************************************************************************/
// blender interface
//#if ELBEEM_BLENDER==1
//extern "C" { void simulateThreadIncreaseFrame(void); }
//#endif // ELBEEM_BLENDER==1
int ntlWorld::renderAnimation( void )
{
// only single pic currently
@ -297,10 +292,6 @@ int ntlWorld::renderAnimation( void )
for( ; ((mFrameCnt<mpGlob->getAniFrames()) && (!getStopRenderVisualization() ) && (simok)); mFrameCnt++) {
if(!advanceSims(mFrameCnt)) {
renderScene();
//#if ELBEEM_BLENDER==1
// update Blender gui display after each frame
//simulateThreadIncreaseFrame();
//#endif // ELBEEM_BLENDER==1
} // else means sim panicked, so dont render...
else { simok=false; }
}
@ -416,11 +407,6 @@ int ntlWorld::advanceSims(int framenum)
}
int gstate = 0;
//#if ELBEEM_BLENDER==1
// same as solver_main check, but no mutex check here
//gstate = getGlobalBakeState();
//if(gstate<0) { allPanic = true; done = true; } // this means abort... cause panic
//#endif // ELBEEM_BLENDER==1
myTime_t advsstart = getTime();
// step all the sims, and check for panic

@ -79,6 +79,7 @@ void SimulationObject::initGeoTree() {
char treeFlag = (1<<(mGeoInitId+4));
mpGiTree = new ntlTree( 20, 4, // warning - fixed values for depth & maxtriangles here...
scene, treeFlag );
exit(1); // unused!? overriden by solver interface
}
/*****************************************************************************/
@ -269,7 +270,7 @@ int SimulationObject::initializeLbmSimulation(ntlRenderGlobals *glob)
}
#ifdef ELBEEM_PLUGIN
mShowParticles=1;
mShowParticles=1; // for e.g. dumping
#endif // ELBEEM_PLUGIN
if((mpLbm->getGenerateParticles()>0.0)||(mpParts->getNumInitialParticles()>0)) {
mShowParticles=1;
@ -288,6 +289,7 @@ int SimulationObject::initializeLbmSimulation(ntlRenderGlobals *glob)
debugObjs[i]->setReceiveShadows( false );
debugObjs[i]->searchMaterial( glob->getMaterials() );
mObjects.push_back( debugObjs[i] );
debMsgStd("SimulationObject::init",DM_NOTIFY,"Added debug obj "<<debugObjs[i]->getName(), 10 );
}
return 0;
}

@ -466,14 +466,7 @@ void LbmFsgrSolver::parseAttrList()
mInitSurfaceSmoothing = mpSifAttrs->readInt("initsurfsmooth", mInitSurfaceSmoothing, "SimulationLbm","mInitSurfaceSmoothing", false );
mSmoothSurface = mpSifAttrs->readFloat("smoothsurface", mSmoothSurface, "SimulationLbm","mSmoothSurface", false );
mSmoothNormals = mpSifAttrs->readFloat("smoothnormals", mSmoothNormals, "SimulationLbm","mSmoothNormals", false );
mFsSurfGenSetting = mpSifAttrs->readInt("fssurfgen", mFsSurfGenSetting, "SimulationLbm","mFsSurfGenSetting", false );
if(mFsSurfGenSetting==-1) {
// all on
mFsSurfGenSetting =
fssgNormal | fssgNoNorth | fssgNoSouth | fssgNoEast |
fssgNoWest | fssgNoTop | fssgNoBottom | fssgNoObs ;
}
// refinement
mMaxRefine = mRefinementDesired;
@ -524,9 +517,7 @@ void LbmFsgrSolver::parseAttrList()
mUseTestdata = 0;
if(mFarFieldSize>=2.) mUseTestdata=1; // equiv. to test solver check
#endif // LBM_INCLUDE_TESTSOLVERS!=1
//if(mUseTestdata) { mMaxRefine=0; } // force fsgr off
if(mMaxRefine==0) mInitialCsmago=0.02;
mInitialCsmago = mpSifAttrs->readFloat("csmago", mInitialCsmago, "SimulationLbm","mInitialCsmago", false );
// deprecated!
float mInitialCsmagoCoarse = 0.0;
@ -562,19 +553,33 @@ void LbmFsgrSolver::initLevelOmegas()
}
}
LbmFloat fineCsmago = mInitialCsmago;
LbmFloat coarseCsmago = mInitialCsmago;
LbmFloat maxFineCsmago1 = 0.026;
LbmFloat maxCoarseCsmago1 = 0.029; // try stabilizing
LbmFloat maxFineCsmago2 = 0.028;
LbmFloat maxCoarseCsmago2 = 0.032; // try stabilizing some more
if((mMaxRefine==1)&&(mInitialCsmago<maxFineCsmago1)) {
fineCsmago = maxFineCsmago1;
coarseCsmago = maxCoarseCsmago1;
}
if((mMaxRefine>1)&&(mInitialCsmago<maxFineCsmago2)) {
fineCsmago = maxFineCsmago2;
coarseCsmago = maxCoarseCsmago2;
}
// use Tau instead of Omega for calculations
{ // init base level
int i = mMaxRefine;
mLevel[i].omega = mOmega;
mLevel[i].timestep = mpParam->getTimestep();
mLevel[i].lcsmago = mInitialCsmago; //CSMAGO_INITIAL;
mLevel[i].lcsmago = fineCsmago; //CSMAGO_INITIAL;
mLevel[i].lcsmago_sqr = mLevel[i].lcsmago*mLevel[i].lcsmago;
mLevel[i].lcnu = (2.0* (1.0/mLevel[i].omega)-1.0) * (1.0/6.0);
}
// init all sub levels
LbmFloat coarseCsmago = mInitialCsmago;
coarseCsmago = 0.04; // try stabilizing
for(int i=mMaxRefine-1; i>=0; i--) {
//mLevel[i].omega = 2.0 * (mLevel[i+1].omega-0.5) + 0.5;
double nomega = 0.5 * ( (1.0/(double)mLevel[i+1].omega) -0.5) + 0.5;
@ -635,6 +640,12 @@ bool LbmFsgrSolver::initializeSolverMemory()
mSizey *= mCppfStage;
mSizez *= mCppfStage;
}
if(mFsSurfGenSetting==-1) {
// all on
mFsSurfGenSetting =
fssgNormal | fssgNoNorth | fssgNoSouth | fssgNoEast |
fssgNoWest | fssgNoTop | fssgNoBottom | fssgNoObs ;
}
// size inits to force cubic cells and mult4 level dimensions
// and make sure we dont allocate too much...

@ -392,6 +392,9 @@ class LbmSolverInterface
inline bool getDumpRawBinary() const { return mDumpRawBinary; }
inline void setDumpRawBinaryZip(bool set) { mDumpRawBinaryZip = set; }
inline bool getDumpRawBinaryZip() const { return mDumpRawBinaryZip; }
//! set/get debug vel scale
inline void setDebugVelScale(LbmFloat set) { mDebugVelScale = set; }
inline LbmFloat getDebugVelScale() const { return mDebugVelScale; }
// cell iterator interface

@ -862,7 +862,7 @@ void LbmFsgrSolver::advanceParticles() {
//&&(!(RFLAG(level, i,j,k, workSet)& CFNoNbFluid))
) {
// add to no nb fluid i.f.'s, so skip if interface with fluid nb
} else if(pflag & (CFFluid|CFUnused|CFInter) ){
} else if(pflag & (CFFluid|CFUnused|CFInter) ){ // interface cells ignored here due to previous check!
// add dropmass again, (these are only interf. with nonbfl.)
int oi= (int)(pos[0]-1.25*v[0]+0.5);
int oj= (int)(pos[1]-1.25*v[1]+0.5);
@ -870,13 +870,17 @@ void LbmFsgrSolver::advanceParticles() {
const LbmFloat size = p->getSize();
const LbmFloat dropmass = ParticleObject::getMass(mPartDropMassSub*size);
bool orgcellok = false;
if( RFLAG(level, oi,oj,ok, workSet) & (CFInter) ){
if( (oi<0)||(oi>mSizex-1)||
(oj<0)||(oj>mSizey-1)||
(ok<0)||(ok>mSizez-1) ) {
// org cell not ok!
} else if( RFLAG(level, oi,oj,ok, workSet) & (CFInter) ){
orgcellok = true;
} else {
// search upward for interface
oi=i; oj=j; ok=k;
for(int kk=0; kk<5 && ok<=mSizez-1; kk++) {
ok++;
for(int kk=0; kk<5 && ok<=mSizez-2; kk++) {
ok++; // check sizez-2 due to this increment!
if( RFLAG(level, oi,oj,ok, workSet) & (CFInter) ){
kk = 5; orgcellok = true;
}

@ -441,15 +441,6 @@ static int fluidsimSimulateThread(void *unused) { // *ptr) {
return ret;
}
// called by simulation to set frame no.
// TODO deprecate...
void simulateThreadIncreaseFrame(void) {
/*if(!globalBakeLock) return;
if(globalBakeState!=0) return; // this means abort...
SDL_mutexP(globalBakeLock);
globalBakeFrame++;
SDL_mutexV(globalBakeLock);*/
}
int runSimulationCallback(void *data, int status, int frame) {
//elbeemSimulationSettings *settings = (elbeemSimulationSettings*)data;
@ -967,6 +958,7 @@ void fluidsimBake(struct Object *ob)
int numVerts=0, numTris=0;
int o = channelObjCount;
int deform = (obit->fluidsimSettings->domainNovecgen); // misused value
// todo - use blenderInitElbeemMesh
elbeemMesh fsmesh;
elbeemResetMesh( &fsmesh );
fsmesh.type = obit->fluidsimSettings->type;;