Skip to content
Snippets Groups Projects
MinMax.cpp 3.85 KiB
Newer Older
Christophe Geuzaine's avatar
Christophe Geuzaine committed
// Gmsh - Copyright (C) 1997-2014 C. Geuzaine, J.-F. Remacle
Christophe Geuzaine's avatar
Christophe Geuzaine committed
//
// See the LICENSE.txt file for license information. Please report all
Christophe Geuzaine's avatar
Christophe Geuzaine committed
// bugs and problems to the public mailing list <gmsh@geuz.org>.
Christophe Geuzaine's avatar
Christophe Geuzaine committed

#include "MinMax.h"
#include "PViewOptions.h"

StringXNumber MinMaxOptions_Number[] = {
Francois Henrotte's avatar
Francois Henrotte committed
  {GMSH_FULLRC, "View", NULL, -1.},
  {GMSH_FULLRC, "OverTime", NULL, 0},
  {GMSH_FULLRC, "Argument", NULL, 0}
Christophe Geuzaine's avatar
Christophe Geuzaine committed
};

extern "C"
{
  GMSH_Plugin *GMSH_RegisterMinMaxPlugin()
  {
    return new GMSH_MinMaxPlugin();
  }
}

std::string GMSH_MinMaxPlugin::getHelp() const
{
  return "Plugin(MinMax) computes the min/max of a view.\n\n"
    "If `View' < 0, the plugin is run on the current view.\n\n"
    "If `OverTime' = 1, calculates the min/max over space AND time\n\n"
    "If `Argument' = 1, calculates the min/max AND the argmin/argmax\n\n"
Christophe Geuzaine's avatar
pp  
Christophe Geuzaine committed
    "Plugin(MinMax) creates two new views.";
Christophe Geuzaine's avatar
Christophe Geuzaine committed
}

int GMSH_MinMaxPlugin::getNbOptions() const
{
  return sizeof(MinMaxOptions_Number) / sizeof(StringXNumber);
}

StringXNumber *GMSH_MinMaxPlugin::getOption(int iopt)
{
  return &MinMaxOptions_Number[iopt];
}

PView *GMSH_MinMaxPlugin::execute(PView * v)
{
  int iView = (int)MinMaxOptions_Number[0].def;
Francois Henrotte's avatar
Francois Henrotte committed
  int overTime = (int)MinMaxOptions_Number[1].def;
  int argument = (int)MinMaxOptions_Number[2].def;
Christophe Geuzaine's avatar
Christophe Geuzaine committed
  PView *v1 = getView(iView, v);
  if(!v1) return v;

  PViewData *data1 = v1->getData(true);
Christophe Geuzaine's avatar
Christophe Geuzaine committed
  PView *vMin = new PView();
  PView *vMax = new PView();
  PViewDataList *dataMin = getDataList(vMin);
  PViewDataList *dataMax = getDataList(vMax);
  if(!argument){
    double x = data1->getBoundingBox().center().x();
    double y = data1->getBoundingBox().center().y();
    double z = data1->getBoundingBox().center().z();
    dataMin->SP.push_back(x); dataMin->SP.push_back(y); dataMin->SP.push_back(z);
    dataMax->SP.push_back(x); dataMax->SP.push_back(y); dataMax->SP.push_back(z);
    dataMin->NbSP = 1;
    dataMax->NbSP = 1;
  }

  double min=VAL_INF, max=-VAL_INF, timeMin=0, timeMax=0;
Francois Henrotte's avatar
Francois Henrotte committed

Christophe Geuzaine's avatar
Christophe Geuzaine committed
  for(int step = 0; step < data1->getNumTimeSteps(); step++){
    if(data1->hasTimeStep(step)){
      double minView = VAL_INF, maxView = -VAL_INF;
      double xmin = 0., ymin = 0., zmin = 0., xmax = 0., ymax = 0., zmax = 0.;
      for(int ent = 0; ent < data1->getNumEntities(step); ent++){
	for(int ele = 0; ele < data1->getNumElements(step, ent); ele++){
	  for(int nod = 0; nod < data1->getNumNodes(step, ent, ele); nod++){
	    double val;
	    data1->getScalarValue(step, ent, ele, nod, val);
	      data1->getNode(step, ent, ele, nod, xmin, ymin, zmin);
	      data1->getNode(step, ent, ele, nod, xmax, ymax, zmax);
Francois Henrotte's avatar
Francois Henrotte committed
      }
	if(argument){
	  dataMin->SP.push_back(xmin); dataMin->SP.push_back(ymin); dataMin->SP.push_back(zmin);
	  dataMax->SP.push_back(xmax); dataMax->SP.push_back(ymax); dataMax->SP.push_back(zmax);
	  (dataMin->NbSP)++;
	  (dataMax->NbSP)++;
	}
        else{
          double time = data1->getTime(step);
          dataMin->Time.push_back(time);
          dataMax->Time.push_back(time);
        }
	dataMin->SP.push_back(minView);
	dataMax->SP.push_back(maxView);
Francois Henrotte's avatar
Francois Henrotte committed
      }
	if(minView < min){
	  min = minView;
	  timeMin = data1->getTime(step);
	}
	if(maxView > max){
	  max = maxView;
	  timeMax = data1->getTime(step);
Francois Henrotte's avatar
Francois Henrotte committed
      }
Francois Henrotte's avatar
Francois Henrotte committed
    dataMin->SP.push_back(min);
    dataMax->SP.push_back(max);
    dataMin->Time.push_back(timeMin);
    dataMax->Time.push_back(timeMax);
Christophe Geuzaine's avatar
Christophe Geuzaine committed
  vMin->getOptions()->intervalsType = PViewOptions::Numeric;
  vMax->getOptions()->intervalsType = PViewOptions::Numeric;
Francois Henrotte's avatar
Francois Henrotte committed

Christophe Geuzaine's avatar
Christophe Geuzaine committed
  dataMin->setName(data1->getName() + "_Min");
  dataMin->setFileName(data1->getName() + "_Min.pos");
  dataMin->finalize();
  dataMax->setName(data1->getName() + "_Max");
  dataMax->setFileName(data1->getName() + "_Max.pos");
  dataMax->finalize();
Christophe Geuzaine's avatar
Christophe Geuzaine committed
  return 0;
}