some fixes in Fem
This commit is contained in:
@@ -37,21 +37,29 @@ PyObject* ViewProviderFemMeshPy::animate(PyObject * args)
|
||||
|
||||
App::Color calcColor(double value,double min, double max)
|
||||
{
|
||||
if (max < 0) max = 0;
|
||||
if (min > 0) min = 0;
|
||||
|
||||
if (value < min)
|
||||
return App::Color (0.0,1.0,0.0);
|
||||
return App::Color (0.0,0.0,1.0);
|
||||
if (value > max)
|
||||
return App::Color (1.0,0.0,0.0);
|
||||
if ( value < (min + (max-min)/2.0 ))
|
||||
return App::Color ((value-min) / ((max-min)/2.0),1.0,0.0) ;
|
||||
else
|
||||
return App::Color (1.0,1-((value-min-((max-min)/2.0)) / ((max-min)/2.0)),0.0);
|
||||
if ( value > max/2.0 )
|
||||
return App::Color (1.0,1-((value-(max/2.0)) / (max/2.0)),0.0);
|
||||
if ( value > 0.0 )
|
||||
return App::Color (value/(max/2.0),1.0,0.0) ;
|
||||
if ( value < min/2.0 )
|
||||
return App::Color (0.0,1-((value-(min/2.0)) / (min/2.0)),1.0);
|
||||
if ( value < 0.0 )
|
||||
return App::Color (0.0,1.0,value/(min/2.0)) ;
|
||||
}
|
||||
|
||||
|
||||
PyObject* ViewProviderFemMeshPy::setNodeColorByResult(PyObject *args)
|
||||
{
|
||||
PyObject *object=0;
|
||||
if (PyArg_ParseTuple(args,"O!",&(App::DocumentObjectPy::Type), &object)) {
|
||||
int type = 0;
|
||||
if (PyArg_ParseTuple(args,"O!|i",&(App::DocumentObjectPy::Type), &object, &type)) {
|
||||
App::DocumentObject* obj = static_cast<App::DocumentObjectPy*>(object)->getDocumentObjectPtr();
|
||||
if (obj && obj->getTypeId().isDerivedFrom(Fem::FemResultValue::getClassTypeId())){
|
||||
Fem::FemResultValue *result = static_cast<Fem::FemResultValue*>(obj);
|
||||
@@ -77,16 +85,40 @@ PyObject* ViewProviderFemMeshPy::setNodeColorByResult(PyObject *args)
|
||||
const std::vector<long> & Ids = result->ElementNumbers.getValues() ;
|
||||
const std::vector<Base::Vector3d> & Vecs = result->Values.getValues() ;
|
||||
std::vector<App::Color> NodeColors(Vecs.size());
|
||||
float max = 0.0;
|
||||
for(std::vector<Base::Vector3d>::const_iterator it= Vecs.begin();it!=Vecs.end();++it)
|
||||
if(it->Length() > max)
|
||||
max = it->Length();
|
||||
double max = -1e12;
|
||||
double min = +1e12;
|
||||
for(std::vector<Base::Vector3d>::const_iterator it= Vecs.begin();it!=Vecs.end();++it){
|
||||
double val;
|
||||
if(type == 0)
|
||||
val = it->Length();
|
||||
else if (type == 1)
|
||||
val = it->x;
|
||||
else if (type == 2)
|
||||
val = it->y;
|
||||
else if (type == 3)
|
||||
val = it->z;
|
||||
else
|
||||
val = it->Length();
|
||||
|
||||
if(val > max)
|
||||
max = val;
|
||||
if(val < min)
|
||||
min = val;
|
||||
}
|
||||
// fill up color vector
|
||||
long i=0;
|
||||
for(std::vector<Base::Vector3d>::const_iterator it= Vecs.begin();it!=Vecs.end();++it,i++)
|
||||
NodeColors[i] = calcColor(it->Length(),0.0,max);
|
||||
|
||||
if(type == 0)
|
||||
NodeColors[i] = calcColor(it->Length(),0.0,max);
|
||||
else if (type == 1)
|
||||
NodeColors[i] = calcColor(it->x,0.0,max);
|
||||
else if (type == 2)
|
||||
NodeColors[i] = calcColor(it->y,0.0,max);
|
||||
else if (type == 3)
|
||||
NodeColors[i] = calcColor(it->z,0.0,max);
|
||||
else
|
||||
NodeColors[i] = calcColor(it->Length(),0.0,max);
|
||||
|
||||
// set the color to the view-provider
|
||||
this->getViewProviderFemMeshPtr()->setColorByNodeId(Ids,NodeColors);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user