示例#1
0
int TopologicalGraph::BFS(svector<int> &comp)
  {comp.clear();
  if(!nv()) return -1;
  tvertex v,w;
  tbrin b,b0;
  int ncc = 0;
  svector<tvertex> stack(1,nv()); stack.SetName("TG:BFS:stack");
  int rank =0;
  int max_rank = 0;
  tvertex v0 = 1;

  while (max_rank < nv())
      {while (comp[v0]) v0++;  
      comp[v0] = ++ncc;
      ++max_rank;
      stack[rank + 1] = v0;

      while(rank < max_rank)
          {v = stack[++rank];  
          b = b0 = pbrin[v];
          if (b0!=0)
              do {w = vin[-b]; 
              if(!comp[w])
                  {comp[w] = ncc; 
                  stack[++max_rank] = w;
                  }
              }while((b = cir[b])!= b0);
          }
      }
  return ncc;
  }
示例#2
0
 /// Destructor.
 CVodeInt::~CVodeInt()
 {   
   if (m_cvode_mem) CVodeFree(m_cvode_mem);
   if (m_y) N_VFree(nv(m_y));
   if (m_abstol) N_VFree(nv(m_abstol));
   delete[] m_iopt;
 }
示例#3
0
  void CVodeInt::initialize(double t0, FuncEval& func) 
  {
    m_neq = func.neq();
    m_t0  = t0;

    if (m_y) {
      N_VFree(nv(m_y));    // free solution vector if already allocated
    }
    m_y = reinterpret_cast<void*>(N_VNew(m_neq, 0));   // allocate solution vector
    // check abs tolerance array size
    if (m_itol == 1 && m_nabs < m_neq) 
      throw CVodeErr("not enough absolute tolerance values specified.");
    func.getInitialConditions(m_t0, m_neq, N_VDATA(nv(m_y)));

    // set options
    m_iopt[MXSTEP] = m_maxsteps;
    m_iopt[MAXORD] = m_maxord;
    m_ropt[HMAX]   = m_hmax;

    if (m_cvode_mem) CVodeFree(m_cvode_mem);

    // pass a pointer to func in m_data 
    m_data = (void*)&func;

    if (m_itol) {
      m_cvode_mem = CVodeMalloc(m_neq, cvode_rhs, m_t0, nv(m_y), m_method, 
				m_iter, m_itol, &m_reltol,
				nv(m_abstol), m_data, NULL, TRUE, m_iopt, 
				DATA_PTR(m_ropt), NULL);
    }
    else {
      m_cvode_mem = CVodeMalloc(m_neq, cvode_rhs, m_t0, nv(m_y), m_method, 
				m_iter, m_itol, &m_reltol,
				&m_abstols, m_data, NULL, TRUE, m_iopt, 
				DATA_PTR(m_ropt), NULL);
    }

    if (!m_cvode_mem) throw CVodeErr("CVodeMalloc failed.");

    if (m_type == DENSE + NOJAC) {
      CVDense(m_cvode_mem, NULL, NULL);
    }
    else if (m_type == DENSE + JAC) {
      CVDense(m_cvode_mem, cvode_jac, NULL);
    }
    else if (m_type == DIAG) {
      CVDiag(m_cvode_mem);
    }
    else if (m_type == GMRES) {
      CVSpgmr(m_cvode_mem, NONE, MODIFIED_GS, 0, 0.0,
	      NULL, NULL, NULL);
    }
    else {
      throw CVodeErr("unsupported option");
    }
  }
示例#4
0
 void CVodeInt::setTolerances(double reltol, int n, double* abstol) {
   m_itol = 1;
   m_nabs = n;
   if (n != m_neq) {
     if (m_abstol) N_VFree(nv(m_abstol));
     m_abstol = reinterpret_cast<void*>(N_VNew(n, 0));
   }
   for (int i=0; i<n; i++) {
     N_VIth(nv(m_abstol), i) = abstol[i];
   }
   m_reltol = reltol; 
 }
示例#5
0
 void CVodesIntegrator::setTolerances(double reltol, int n, double* abstol) {
   m_itol = CV_SV;
   m_nabs = n;
   if (n != m_neq) {
     if (m_abstol) N_VDestroy_Serial(nv(m_abstol));
     m_abstol = reinterpret_cast<void*>(N_VNew_Serial(n));
   }
   for (int i=0; i<n; i++) {
     NV_Ith_S(nv(m_abstol), i) = abstol[i];
   }
   m_reltol = reltol; 
 }
示例#6
0
  /// Destructor.
  CVodesIntegrator::~CVodesIntegrator()
  {   
    if (m_cvode_mem) {
      if (m_np > 0) 
	CVodeSensFree(m_cvode_mem);
      CVodeFree(&m_cvode_mem);
    }
    if (m_y) N_VDestroy_Serial(nv(m_y));
    if (m_abstol) N_VDestroy_Serial(nv(m_abstol));
    delete m_fdata;

    //delete[] m_iopt;
  }
示例#7
0
int ImCAMSim::doSimulation()
{
   ImClData *sp,*ep;
   sp = m_clPath->getPath();
   ImPoint3Dd nv(0.0,0.0,1.0);
   ImPoint3Dd *nv1 = NULL;
   ImPoint3Dd *nv2 = NULL;
   for(ep = sp->getNextCl(); ep != NULL; ep = ep->getNextCl()){
      // segment
      
      if(IM_CL_SEGMENT == ep->getType()){
         nv1 = sp->getDirection();
         if(NULL == nv1){
            nv1 = &nv;
         }
         nv2 = ep->getDirection();
         if(NULL == nv2){
            nv2 = &nv;
         }
         //::EnterCriticalSection(&m_cs);
         m_cs_.Lock();
         g_Store.simCutBySegment(m_currentID,*(sp->getEndPoint()), *nv1,
            *(ep->getEndPoint()),*nv2);
         m_cs_.Unlock();
        //  ::LeaveCriticalSection(&m_cs);
      }
      sp = ep;
      ::SendMessage(m_pViewHandle, IM3DEDITOR_SIMULATION_UPDATEVIEW, (WPARAM)0/*idx*/, (LPARAM)0);
   }
   ::SendMessage(m_pViewHandle, IM3DEDITOR_SIMULATION_UPDATEVIEW, (WPARAM)0/*idx*/, (LPARAM)0);
   return 0;
}
示例#8
0
                RiemannianDanek<N,T>& RiemannianDanek<N,T>::SetTransformationMatrix
                    (const Math::Algebra::SquareMatrix<N,T> &mt)
                {
                    // Calculate delta phi of the transformed neighbourhood                    
                    System::Collection::Array<1,Math::Algebra::Vector<N,T> > nv(m_nb.Elements());                    
                    
                    for (Size i = 0; i < m_nb.Elements(); i++)
                    {
                        nv[i] = mt.Mul(m_nb[i]).Normalized();
                    }

                    System::Collection::Array<1,T> dphi;
                    Math::Geometry::HypersphereVoronoiDiagram(nv, dphi);

                    // Calculate delta rho and capacities
                    T coef = CauchyCroftonCoef<N,T>();
                    T cell_area = mt.Determinant();
                    
                    for (Size i = 0; i < m_nb.Elements(); i++)
                    {
                        T drho = cell_area / mt.Mul(m_nb[i]).Length();
                        m_rw[i] = (dphi[i] * drho) / coef;
                    }

                    return *this;
                }
示例#9
0
int TopologicalGraph::ExpandEdges()
{ 
  int nadded=0;
  int morig=ne();
  tedge e;
  int i;
  if (!Set(tedge()).exist(PROP_MULTIPLICITY)) return 0;
  Prop<int>  multiplicity(Set(tedge()),PROP_MULTIPLICITY);
  for (e=1; e<=morig; e++)
    {for (i=2; i<=multiplicity[e]; ++i)
      NewEdge(e.firsttbrin(), e.secondtbrin());
    nadded+=multiplicity[e]-1;
    }
  Set(tedge()).erase(PROP_MULTIPLICITY);
  // add loops
  if (!Set(tvertex()).exist(PROP_NLOOPS))
    return nadded;
  tvertex v;
  Prop<int> nloops(Set(tvertex()),PROP_NLOOPS);
  for (v=1; v<=nv(); ++v)
    for (i=1; i<=nloops[v]; ++i)
      {++nadded;
      NewEdge(v,v);
      }
  Set(tvertex()).erase(PROP_NLOOPS);
  return nadded;
}
示例#10
0
void MultiObjectSeg::buildKdTree(Sample& smp)
{
	if (downSample != NULL)
	{
		delete downSample;
	}

	downSample = new Sample();

	IndexType i = 0;

	IndexType vSize = smp.num_vertices();

	for(; i < vSize; ++ i)
	{
		Vertex& vtx = smp[i];

		PointType v( vtx.x(), vtx.y(), vtx.z() );
		ColorType cv(vtx.r(), vtx.g(), vtx.b(), vtx.alpha());
		NormalType nv(vtx.nx(), vtx.ny(), vtx.nz());

		downSample->add_vertex(v,nv,cv);

	}

	downSample->build_kdtree();

}
示例#11
0
void SemiconductorPhase::getChemPotentials(doublereal* mu) const
{
    getActivityConcentrations(DATA_PTR(m_work));
    doublereal r = m_work[0]/nc();
    mu[0] = ec() + GasConstant*temperature()*(JoyceDixon(r));
    mu[1] = ev() + GasConstant*temperature()*(log(m_work[1]/nv()));
}
	void GameBodyObject::render(float) 
	{
	#if (NX_UNSTABLE_USE_SCENE_ACTIVE_TRANSFORM == 1)

		NxMat34 nm = mActor->getGlobalPose();
		NxVec3 nv(nm.t);
		NxQuat nq(nm.M);
		if (mNode != NULL)
		{
			mNode->setPosition(nv.x, nv.y, nv.z);
			mNode->setOrientation(nq.w,nq.x,nq.y,nq.z);
		}
		shapeRender(0);
	#else
		if ((mActor != NULL) && (mNode != NULL))
		{
			mNode->setPosition(getGlobalPosition());
			mNode->setOrientation(getGlobalOrientation());
			shapeRender(dT);
		}	
	#endif

		// Update the prevGlobalTransform value
		if (mNode != NULL)
		{
			prevGlobalPosition = mNode->_getDerivedPosition();
			prevGlobalOrientation = mNode->_getDerivedOrientation();
		}
	}
示例#13
0
	truss initTruss(std::vector<float > x){
		
		std::vector<node > nv(6);

		for(int nn=0;nn<6;nn++){
			nv.at(nn) = node(x.at(2*nn),x.at(2*nn+1),nn);
		}
		std::vector<rod> trussRods(8);

		trussRods.at(0) = rod(nv.at(0),nv.at(4));
		trussRods.at(1) = rod(nv.at(0),nv.at(1));
		trussRods.at(2) = rod(nv.at(1),nv.at(4));
		trussRods.at(3) = rod(nv.at(1),nv.at(2));
		trussRods.at(4) = rod(nv.at(1),nv.at(5));
		trussRods.at(5) = rod(nv.at(2),nv.at(5));
		trussRods.at(6) = rod(nv.at(2),nv.at(4));
		trussRods.at(7) = rod(nv.at(3),nv.at(5));
		
		truss truss1 = truss(trussRods);
		
		truss1.fixXY(0);
		truss1.fixXY(3);
		
		Eigen::VectorXf v(12);
		v(2) = 1;
		v(4) = 1;
		truss1.setLoads(v);
		
		return truss1;
	}
示例#14
0
  void CVodeInt::reinitialize(double t0, FuncEval& func) 
  {
    m_t0  = t0;
    func.getInitialConditions(m_t0, m_neq, N_VDATA(nv(m_y)));

    // set options
    m_iopt[MXSTEP] = m_maxsteps;
    m_iopt[MAXORD] = m_maxord;
    m_ropt[HMAX]   = m_hmax;

    //if (m_cvode_mem) CVodeFree(m_cvode_mem);

    // pass a pointer to func in m_data 
    m_data = (void*)&func;
    int result;
    if (m_itol) {
      result = CVReInit(m_cvode_mem, cvode_rhs, m_t0, nv(m_y), m_method, 
			m_iter, m_itol, &m_reltol,
			nv(m_abstol), m_data, NULL, TRUE, m_iopt, 
			DATA_PTR(m_ropt), NULL);
    }
    else {
      result = CVReInit(m_cvode_mem, cvode_rhs, m_t0, nv(m_y), m_method, 
			m_iter, m_itol, &m_reltol,
			&m_abstols, m_data, NULL, TRUE, m_iopt, 
			DATA_PTR(m_ropt), NULL);
    }

    if (result != 0) throw CVodeErr("CVReInit failed.");

    if (m_type == DENSE + NOJAC) {
      CVDense(m_cvode_mem, NULL, NULL);
    }
    else if (m_type == DENSE + JAC) {
      CVDense(m_cvode_mem, cvode_jac, NULL);
    }
    else if (m_type == DIAG) {
      CVDiag(m_cvode_mem);
    }
    else if (m_type == GMRES) {
      CVSpgmr(m_cvode_mem, NONE, MODIFIED_GS, 0, 0.0,
	      NULL, NULL, NULL);
    }
    else {
      throw CVodeErr("unsupported option");
    }
  }
示例#15
0
 void CVodeInt::integrate(double tout)
 {
   double t;
   int flag;
   flag = CVode(m_cvode_mem, tout, nv(m_y), &t, NORMAL);
   if (flag != SUCCESS) 
     throw CVodeErr(" CVode error encountered.");
 }
示例#16
0
 double CVodeInt::step(double tout)
 {
   double t;
   int flag;
   flag = CVode(m_cvode_mem, tout, nv(m_y), &t, ONE_STEP);
   if (flag != SUCCESS) 
     throw CVodeErr(" CVode error encountered.");
   return t;
 }
示例#17
0
 double CVodesIntegrator::step(double tout)
 {
   double t;
   int flag;
   flag = CVode(m_cvode_mem, tout, nv(m_y), &t, CV_ONE_STEP);
   if (flag != CV_SUCCESS) 
     throw CVodesErr(" CVodes error encountered.");
   return t;
 }
示例#18
0
bool TopologicalGraph::CheckSimple()
  {if(debug())DebugPrintf("   CheckSimple");
  if(Set().exist(PROP_SIMPLE))return true;
  if(ne() <= 1){Prop1<int> simple(Set(),PROP_SIMPLE);return true;}
  if(debug())DebugPrintf("Executing CheckSimple");
  if(!CheckNoLoops())return false;
  
  svector<tedge>link(1,ne()); link.clear(); link.SetName("CheckSimple:link");
  svector<tedge>top1(1,nv()); top1.clear(); top1.SetName("CheckSimple:link");
  svector<tedge>top2(1,nv()); top2.clear(); top2.SetName("CheckSimple:link");
  tvertex u,v,w;
  tedge e,next;
  //First sort with respect to biggest label
  for(e = ne();e >= 1;e--)
      {v = (vin[e] < vin[-e]) ? vin[-e] : vin[e];
      link[e] = top1[v];top1[v] = e;
      }
  // Then sort with respect to smallest label
  for(u = nv();u > 1;u--)
      {e = top1[u];
      while(e!=0)
          {next = link[e];     //as link is modified
          v = (vin[e] < vin[-e]) ? vin[e] : vin[-e];
          link[e] = top2[v]; top2[v] = e;
          e = next;
          }
      }
  // Check Multiple edges
  for(v = nv()-1;v >= 1;v--)
      {e = top2[v];
      while(e!=0)
          {next = link[e];
          u = vin[e];    if(u == v)u = vin[-e];
          w = vin[next]; if(w == v)w = vin[-next];
          if(u == w)
              return false;
          else
              link[e] = 0;
          e = next;
          }
      }
  Prop1<int> simple(Set(),PROP_SIMPLE);
  return true;
  }
 void MediaTypeStream::write_eof()
 {
     if (this->state == State::value_state)
     {
         NameValueCollection::value_type nv(this->name, this->value);
         this->mediaType->parameters->insert(nv);
         this->name = 0;
         this->value = 0;
     }
 }
示例#20
0
 virtual WriteResult writeNode(const osg::Node& node,std::ostream& fout,const Options* =NULL) const 
 { 
     // writing to a stream does not support materials
     
     OBJWriterNodeVisitor nv(fout);
     
     // we must cast away constness
     (const_cast<osg::Node*>(&node))->accept(nv);
 
     return WriteResult(WriteResult::FILE_SAVED); 
 }
示例#21
0
NVCenter create_defect_center(const po::variables_map& para)
{/*{{{*/
    vec coord( para["position"].as<string>() );
    vec magB( para["magnetic_field"].as<string>() );

    NVCenter nv(NVCenter::N14, coord);
    nv.set_magB(magB);
    nv.make_espin_hamiltonian();

    return nv;
}/*}}}*/
void ossimPlanetAnnotationLayer::removeByNameAndId(const ossimString& name, const ossimString& id)
{
   ossimPlanetLayerNameIdSearchVisitor nv(name, id);
   OpenThreads::ScopedLock<OpenThreads::Mutex> lock(theGraphMutex);
   accept(nv);
   ossimPlanetNode* node = dynamic_cast<ossimPlanetNode*>(nv.node().get());
   if(node)
   {
		needsRemoving(node);
   }
}
示例#23
0
bool TopologicalGraph::CheckBiconnected()
  {if(debug())DebugPrintf("   CheckBionnected");
  if(Set().exist(PROP_BICONNECTED))return true;
  if(nv() < 3 || ne() < 3)return false;
  if(debug())DebugPrintf("Executing CheckBionnected");
  int m = ne();
  int n = nv();
  if (m==0) return true;
  svector<tvertex> nvin(-m,m);   nvin.SetName("TG:Bicon:nvin");
  svector<tvertex> low(0,n);     low.SetName("TG:Bicon:low"); 

  if(!DFS(nvin)) // not connected ...
      return false;
  _Bicon Bicon(n);
  int ret = bicon(n,m,nvin,Bicon,low);
  if(ret)
      {Prop1<int> isbicon(Set(),PROP_BICONNECTED);
      Prop1<int> is_con(Set(),PROP_CONNECTED);
      return true;
      }
  return false;
  }
示例#24
0
        virtual WriteResult writeNode(const osg::Node& node,const std::string& fileName,const Options* options =NULL) const
        {
            std::string ext = osgDB::getLowerCaseFileExtension(fileName);
            if( !acceptsExtension(ext)) return WriteResult::FILE_NOT_HANDLED;

            osgDB::ofstream f(fileName.c_str());

            Writer3DCNodeVisitor nv(f);

            // we must cast away constness
            (const_cast<osg::Node*>(&node))->accept(nv);

            return WriteResult::FILE_SAVED;
        }
    virtual WriteResult writeNode(const osg::Node& node,std::ostream& fout,const Options* options=NULL) const
    {
        ObjOptionsStruct localOptions = parseOptions(options);
        fout.precision(localOptions.precision);

        // writing to a stream does not support materials

        OBJWriterNodeVisitor nv(fout);

        // we must cast away constness
        (const_cast<osg::Node*>(&node))->accept(nv);

        return WriteResult(WriteResult::FILE_SAVED);
    }
示例#26
0
void Url::removeHeaderParameter(const char* name)
{
    if(mpHeaderOrQueryParameters || parseHeaderOrQueryParameters())
    {
        NameValuePairInsensitive nv(name ? name : "", NULL);

        UtlDListIterator iterator(*mpHeaderOrQueryParameters);

        UtlContainable* matchingParam;
        while((matchingParam=iterator.findNext(&nv)))
        {
           mpHeaderOrQueryParameters->destroy(matchingParam);
        }
    }
}
示例#27
0
/*private*/
void
MCIndexSnapRounder::checkCorrectness(
	SegmentString::NonConstVect& inputSegmentStrings)
{
	auto_ptr<SegmentString::NonConstVect> resultSegStrings(
		NodedSegmentString::getNodedSubstrings(inputSegmentStrings)
	);

	NodingValidator nv(*(resultSegStrings.get()));
	try {
		nv.checkValid();
	} catch (const std::exception &ex) {
		std::cerr << ex.what() << std::endl;
		throw;
	}
}
示例#28
0
NVCenter create_defect_center(const ConfigXML& cfg)
{
    double x = cfg.getDoubleParameter("CenterSpin",  "coordinate_x");
    double y = cfg.getDoubleParameter("CenterSpin",  "coordinate_y");
    double z = cfg.getDoubleParameter("CenterSpin",  "coordinate_z");
    vec coord; coord << x << y << z;
    NVCenter nv(NVCenter::N14, coord);
    
    double magBx = cfg.getDoubleParameter("Condition",  "magnetic_fieldX");
    double magBy = cfg.getDoubleParameter("Condition",  "magnetic_fieldY");
    double magBz = cfg.getDoubleParameter("Condition",  "magnetic_fieldZ");
    nv.set_magB(magBx, magBy, magBz);
    nv.make_espin_hamiltonian();

    return nv;
}
示例#29
0
 virtual WriteResult writeNode(const osg::Node& node,const std::string& fileName,const Options* options =NULL) const 
 { 
     if (!acceptsExtension(osgDB::getFileExtension(fileName)))
         return WriteResult(WriteResult::FILE_NOT_HANDLED); 
         
     std::ofstream f(fileName.c_str());
     std::string materialFile = osgDB::getNameLessExtension(fileName) + ".mtl";
     OBJWriterNodeVisitor nv(f, osgDB::getSimpleFileName(materialFile));
     
     // we must cast away constness
     (const_cast<osg::Node*>(&node))->accept(nv);
     
     std::ofstream mf(materialFile.c_str());
     nv.writeMaterials(mf);
      
     return WriteResult(WriteResult::FILE_SAVED); 
 }
示例#30
0
文件: kdTree.cpp 项目: PoorniK/kdTree
vector<T> slice(const vector<T>& v, int start=0, int end=-1) {
    int oldlen = v.size();
    int newlen;

    if (end == -1 or end >= oldlen){
        newlen = oldlen-start;
    } else {
        newlen = end-start;
    }

    vector<T> nv(newlen);

    for (int i=0; i<newlen; i++) {
        nv[i] = v[start+i];
    }
    return nv;
}