コード例 #1
0
ファイル: int_object.cpp プロジェクト: Ethon/vanilla
signed long long vanilla::int_object_to_signed_longlong(object::ptr const& obj)
{
#if LLONG_MAX == LONG_MAX
    return int_object_to_signed_long(obj);
#endif
    
    if(obj->type_id() != OBJECT_ID_INT)
    {
        BOOST_THROW_EXCEPTION(error::bad_cast_error()
            << error::first_operand(obj)
            << error::cast_target_name("int"));
    }
    
    mpz_t& mpz = static_cast<int_object const*>(obj.get())->value().mpz();
    if(mpz_sizeinbase(mpz, 2) + 1 > sizeof(long long) * CHAR_BIT)
    {
        BOOST_THROW_EXCEPTION(error::integer_conversion_overflow_error()
            << error::first_operand(obj)
            << error::integer_conversion_target_type("signed long long"));
    }
    
    size_t count = 0;
    long long result = 0;
    mpz_export(&result, &count, -1, sizeof(result), 0, 0, mpz);
    assert(count == 1);
    return result;
}
コード例 #2
0
ファイル: int_object.cpp プロジェクト: Ethon/vanilla
vanilla::object::ptr vanilla::int_object::neq(object::ptr const& other)
{
    switch(other->type_id())
    {
        case OBJECT_ID_INT:
        {
            int_object const* rhs = static_cast<int_object const*>(other.get());
            int result = mpz_cmp(_v.mpz(), rhs->value().mpz());
            return allocate_object<bool_object>(result != 0);
        }
        
        case OBJECT_ID_FLOAT:
        {
            float_object const* rhs = static_cast<float_object const*>(other.get());
            if(!mpf_integer_p(rhs->value().mpf()))
                return allocate_object<bool_object>(true);
            
            float_object::float_type lhs( (_v.mpz()) );
            return allocate_object<bool_object>(mpf_cmp(lhs.mpf(), rhs->value().mpf()) != 0);
        }
        
        default:
        {
            return object::ge(other);
        }
    }
}
コード例 #3
0
ファイル: int_object.cpp プロジェクト: Ethon/vanilla
vanilla::object::ptr vanilla::int_object::div(object::ptr const& other)
{
    switch(other->type_id())
    {
        case OBJECT_ID_INT:
        {
            float_object::float_type lhs( (_v.mpz()) );
            float_object::float_type rhs( (static_cast<int_object const*>(other.get())->value().mpz()) );
            float_object::float_type result;
            mpf_div(result.mpf(), lhs.mpf(), rhs.mpf());
            return allocate_object<float_object>(std::move(result));
        }
        
        case OBJECT_ID_FLOAT:
        {
            float_object::float_type lhs( (_v.mpz()) );
            float_object const* rhs = static_cast<float_object const*>(other.get());
            float_object::float_type result;
            mpf_div(result.mpf(), lhs.mpf(), rhs->value().mpf());
            return allocate_object<float_object>(std::move(result));
        }
        
        default:
        {
            return object::div(other);
        }
    }
}
コード例 #4
0
ファイル: CutGeometry.cpp プロジェクト: vistle/vistle
bool CutGeometry::compute() {

   Object::const_ptr oin = expect<Object>("grid_in");
   if (!oin)
      return false;

   Object::ptr object = cutGeometry(oin);
   if (object) {
      object->copyAttributes(oin);
      addObject("grid_out", object);
   }

   return true;
}
コード例 #5
0
bool IsoSurface::work(vistle::UnstructuredGrid::const_ptr gridS,
             vistle::Vec<vistle::Scalar>::const_ptr dataS,
             vistle::DataBase::const_ptr mapdata) {

   const int processorType = getIntParameter("processortype");
#ifdef CUTTINGSURFACE
   const Scalar isoValue = 0.0;
#else
   const Scalar isoValue = getFloatParameter("isovalue");
#endif

   Leveller l(isocontrol, gridS, isoValue, processorType);

#ifndef CUTTINGSURFACE
   l.setIsoData(dataS);
#endif
   if(mapdata){
      l.addMappedData(mapdata);
   };
   l.process();

#ifndef CUTTINGSURFACE
   auto minmax = dataS->getMinMax();
   if (minmax.first[0] < m_min)
      m_min = minmax.first[0];
   if (minmax.second[0] > m_max)
      m_max = minmax.second[0];
#endif

   Object::ptr result = l.result();
   DataBase::ptr mapresult = l.mapresult();
   if (result) {
#ifndef CUTTINGSURFACE
      result->copyAttributes(dataS);
#endif
      result->copyAttributes(gridS, false);
      if (mapdata && mapresult) {
         mapresult->copyAttributes(mapdata);
         mapresult->setGrid(result);
         addObject(m_dataOut, mapresult);
      }
#ifndef CUTTINGSURFACE
      else {
          addObject(m_dataOut, result);
      }
#endif
   }
   return true;
}
コード例 #6
0
ファイル: ColorAttribute.cpp プロジェクト: xyuan/vistle
bool ColorAttribute::compute() {

   //std::cerr << "ColorAttribute: compute: execcount=" << m_executionCount << std::endl;

   auto color = p_color->getValue();
   Object::const_ptr obj = expect<Object>("data_in");
   if (!obj)
      return false;

   Object::ptr out = obj->clone();
   out->addAttribute("_color", color);
   addObject("data_out", out);

   return true;
}
コード例 #7
0
ファイル: AddAttribute.cpp プロジェクト: vistle/vistle
bool AddAttribute::compute() {

   Object::const_ptr obj = expect<Object>("data_in");
   if (!obj)
      return true;

   Object::ptr out = obj->clone();

   for (int i=0; i<NumAttributes; ++i) {
      if (!p_name[i]->getValue().empty()) {
         out->addAttribute(p_name[i]->getValue(), p_value[i]->getValue());
      }
   }

   addObject("data_out", out);

   return true;
}
コード例 #8
0
ファイル: CellToVert.cpp プロジェクト: xyuan/vistle
bool CellToVert::compute() {

   coCellToVert algo;

   Object::const_ptr grid = expect<Object>("grid_in");
   Object::const_ptr data = expect<Object>("data_in");
   if (!grid || !data)
      return false;

   Object::ptr out = algo.interpolate(grid, data);
   if (out) {
      out->copyAttributes(data);
      addObject("data_out", out);
      passThroughObject("grid_out", grid);
   }

   return true;
}
コード例 #9
0
ファイル: int_object.cpp プロジェクト: Ethon/vanilla
signed long vanilla::int_object_to_signed_long(object::ptr const& obj)
{
    if(obj->type_id() != OBJECT_ID_INT)
    {
        BOOST_THROW_EXCEPTION(error::bad_cast_error()
            << error::first_operand(obj)
            << error::cast_target_name("int"));
    }
    
    mpz_t& mpz = static_cast<int_object const*>(obj.get())->value().mpz();
    if(!mpz_fits_slong_p(mpz))
    {
        BOOST_THROW_EXCEPTION(error::integer_conversion_overflow_error()
            << error::first_operand(obj)
            << error::integer_conversion_target_type("signed long"));
    }
    return mpz_get_si(mpz);
}
コード例 #10
0
bool IsoSurface::compute() {

   const Scalar isoValue = getFloatParameter("isovalue");

   Object::const_ptr grid = expect<Object>("grid_in");
   Object::const_ptr data = expect<Object>("data_in");
   if (!grid || !data)
      return false;

   Object::ptr object = generateIsoSurface(grid, data, isoValue);

   if (object) {
      object->copyAttributes(data);
      object->copyAttributes(grid, false);
      addObject("grid_out", object);
   }

   return true;
}
コード例 #11
0
ファイル: float_object.cpp プロジェクト: Ethon/vanilla
double vanilla::float_object_to_double(object::ptr const& obj)
{
    if(obj->type_id() != OBJECT_ID_FLOAT)
    {
        BOOST_THROW_EXCEPTION(error::bad_cast_error()
            << error::first_operand(obj)
            << error::cast_target_name("float"));
    }
    
    mpf_t& mpf = static_cast<float_object const*>(obj.get())->value().mpf();
    double result = mpf_get_d(mpf);
    if(std::numeric_limits<double>::has_infinity &&
        result == std::numeric_limits<double>::infinity())
    {
        BOOST_THROW_EXCEPTION(error::float_conversion_overflow_error()
            << error::first_operand(obj)
            << error::float_conversion_target_type("double"));
    }
    
    return result;
}
コード例 #12
0
bool FilterNode::compute() {

   Object::const_ptr data = expect<Object>("data_in");
   if (!data)
      return true;

   const bool invert = m_invertParam->getValue();
   const Integer select = m_nodeParam->getValue();

   bool pass = true;
   switch (m_criterionParam->getValue()) {
   case Rank:
       pass = select == rank();
       break;
   case BlockNumber:
       pass = select == data->getBlock();
       break;
   case Timestep:
       pass = select == data->getTimestep();
       break;
   }

   if (invert)
      pass = !pass;

   if (pass) {
      passThroughObject("data_out", data);
   } else {
      Object::ptr obj = data->cloneType();
      obj->setMeta(data->meta());
      obj->copyAttributes(data);
      addObject("data_out", obj);
   }

   return true;
}
コード例 #13
0
ファイル: IsoSurface.cpp プロジェクト: vistle/vistle
bool IsoSurface::work(vistle::Object::const_ptr grid,
             vistle::Vec<vistle::Scalar>::const_ptr dataS,
             vistle::DataBase::const_ptr mapdata) {

   const int processorType = getIntParameter("processortype");
#ifdef CUTTINGSURFACE
   const Scalar isoValue = 0.0;
#else
   const Scalar isoValue = getFloatParameter("isovalue");
#endif

   Leveller l(isocontrol, grid, isoValue, processorType);
   l.setComputeNormals(m_computeNormals->getValue());

#ifndef CUTTINGSURFACE
   l.setIsoData(dataS);
#endif
   if(mapdata){
      l.addMappedData(mapdata);
   };
   l.process();

#ifndef CUTTINGSURFACE
   auto minmax = dataS->getMinMax();
   if (minmax.first[0] < m_min)
      m_min = minmax.first[0];
   if (minmax.second[0] > m_max)
      m_max = minmax.second[0];
#endif

   Object::ptr result = l.result();
   DataBase::ptr mapresult = l.mapresult();
   if (result && !result->isEmpty()) {
#ifndef CUTTINGSURFACE
      result->copyAttributes(dataS);
#endif
      result->updateInternals();
      result->copyAttributes(grid, false);
      result->setTransform(grid->getTransform());
      if (result->getTimestep() < 0) {
          result->setTimestep(grid->getTimestep());
          result->setNumTimesteps(grid->getNumTimesteps());
      }
      if (result->getBlock() < 0) {
          result->setBlock(grid->getBlock());
          result->setNumBlocks(grid->getNumBlocks());
      }
      if (mapdata && mapresult) {
         mapresult->updateInternals();
         mapresult->copyAttributes(mapdata);
         mapresult->setGrid(result);
         addObject(m_dataOut, mapresult);
      }
#ifndef CUTTINGSURFACE
      else {
          addObject(m_dataOut, result);
      }
#endif
   }
   return true;
}