/********************************************************************/ /* Copyright (c) 2017 System fugen G.K. and Yuzi Mizuno */ /* All rights reserved. */ /********************************************************************/ #include "MGCLStdAfx.h" #include "mg/NDDArray.h" #include "mg/Box.h" #include "mg/BPointSeq.h" #include "mg/SPointSeq.h" #include "mg/Vector.h" #include "mg/Matrix.h" #include "mg/Transf.h" #include "mg/Straight.h" #include "mg/Plane.h" #include "mg/Tolerance.h" #include "cskernel/bkdtpg.h" #include "cskernel/Bvavpl.h" #if defined(_DEBUG) #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif // // Implementation of Class MGSPointSeq //Constructor MGSPointSeq::MGSPointSeq(int sizeu, int sizev, int dim) :m_capacityu(sizeu),m_capacityv(sizev),m_sdim(dim) ,m_lengthu(sizeu),m_lengthv(sizev){ int len=sizeu*sizev*dim; if(len) m_spoint=new double[len]; else{ m_capacityu=m_capacityv=m_lengthu=m_lengthv=0; m_spoint=0; } } MGSPointSeq::MGSPointSeq( int dim, // New Space Dimension. const MGSPointSeq& old, // Origianl SpointSeq. int start1, // Destination start order to store. int start2 // Source start order to retrieve. ) //Construct a MGSPointSeq by copying original MGSPointSeq. //Can change the order of coordinates : m_capacityu(old.m_lengthu),m_capacityv(old.m_lengthv) , m_sdim(dim) , m_lengthu(old.m_lengthu), m_lengthv(old.m_lengthv){ assert(start1=dim) k1=0; k2 +=1; if(k2>=dim2) k2=0; } while(k++=dim) k1=0; } }else m_spoint=0; } //Copy constructor. MGSPointSeq::MGSPointSeq(const MGSPointSeq& rhs) : m_capacityu(rhs.m_capacityu),m_capacityv(rhs.m_capacityv) , m_sdim(rhs.m_sdim) , m_lengthu(rhs.m_lengthu), m_lengthv(rhs.m_lengthv) { m_spoint=new double[m_capacityu*m_capacityv*m_sdim]; for(int k=0; k=dijk ? max:dijk; min= min<=dijk ? min:dijk; } } intrvl[k]=MGInterval(min,max); } MGBox ubox; if(dim) ubox=MGBox(dim, intrvl); delete[] intrvl; return ubox; } //Compute minimum box sorrounding the all the points. MGBox* MGSPointSeq::compute_box()const{ int dim=sdim(); MGInterval* intrvl=new MGInterval[dim]; int lenu=length_u(), lenv=length_v(); for(int k=0; k=dijk ? max:dijk; min= min<=dijk ? min:dijk; } } intrvl[k]=MGInterval(min,max); } MGBox* ubox; if(dim) ubox=new MGBox(dim, intrvl); else ubox=new MGBox(); delete[] intrvl; return ubox; } //Returns a pointer to the area. const double* MGSPointSeq::data(int i, int j, int k) const {return &m_spoint[i+m_capacityu*j+m_capacityu*m_capacityv*k];} //Returns a pointer to the area. double* MGSPointSeq::data(int i, int j, int k) {return &m_spoint[i+m_capacityu*j+m_capacityu*m_capacityv*k];} //Transformation for rational(MGRLBRep) Control Polygon. //When rational control polygon, coordinates are of homogeneous form, //i.e., the last space dimension id is for weights, //and other elements include weight multiplied. MGSPointSeq& MGSPointSeq::homogeneous_transform(double scale) //1. Scaling. { --m_sdim; operator*=(scale); ++m_sdim; return *this; } //2. Vector addition. MGSPointSeq& MGSPointSeq::homogeneous_transform(const MGVector& vec) { int i,j,r; int dim1=sdim()-1, dim2=vec.sdim(); int dim= dim1>=dim2 ? dim1:dim2; double* v=new double[dim]; for(j=0; jdim1){ MGSPointSeq bnew(lenu,lenv, dim+1); for(i=0; i=dim2 ? dim1:dim2; int i,j,r1,r2; double a; int lenu=length_u(),lenv=length_v(); if(dim>dim1){ MGSPointSeq bnew(lenu,lenv, dim+1); for(i=0; i=sdim(), return 0.0 . assert(i=sdim()) return 0.; else return m_spoint[i+m_capacityu*j+m_capacityu*m_capacityv*k]; } //Change size. Change of sdim not allowed. void MGSPointSeq::reshape( int sizeu, int sizev , int startu, int startv ){ assert(startu<=sizeu && startv<=sizev); int nlenu=m_lengthu+startu; int nlenv=m_lengthv+startv; if(sizeusd2) len=sd2; for(int r=0; r=sd1) to=0; if(from>=sd2) from=0; m_spoint[i+m_capacityu*j+m_capacityu*m_capacityv*(to++)]=vector.ref(from++); } } //Store vector data vector(from+r) to this(i,j,to+r) for 0<=rsd1) len=sd1; for(int r=0; r=sd1) to=0; if(from>=sd2) from=0; m_spoint[i+m_capacityu*j+m_capacityu*m_capacityv*(to++)]=vector.ref(from++); } } //Store data[r] to this(i,j,to+r) 0<=r=sd1) to=0; m_spoint[i+m_capacityu*j+m_capacityu*m_capacityv*(to++)]=data[r]; } } //Store BPointSeq along u at v's id j. That is, //data bp(i,from+r) to this(i,j,to+r) for i=0,..., length_u()-1, and 0<=rsd2) len=sd2; int szubyj=m_capacityu*j, szubyszv=m_capacityu*m_capacityv; for(int r=0; r=sd1) to=0; if(from>=sd2) from=0; int juvto=szubyj+szubyszv*to; for(int i=0; isd2) len=sd2; int szubyszv=m_capacityu*m_capacityv; for(int r=0; r=sd1) to=0; if(from>=sd2) from=0; int iuvto=i+szubyszv*to; for(int j=0; j=dim2 ? dim1:dim2; double* v=new double[dim]; for(k=0; kdim1){ MGSPointSeq bnew(lenu,lenv, dim); for(k=0; k=dim2 ? dim1:dim2; int i,j,k,k2; double a; int lenu=length_u(), lenv=length_v(); if(dim>dim1){ MGSPointSeq bnew(lenu, lenv, dim); for(i=0; ierror) return 0; } } return 1; } //Add and subtract operation of two MGSPointSeq. MGSPointSeq& MGSPointSeq::operator+= (const MGSPointSeq& sp2){ int sd=sdim(), sd2=sp2.sdim(); if(sd2>sd) sd=sd2; int nu1=length_u(), nu2=sp2.length_u(); int nu=nu1; if(nu2>nu) nu=nu2; int nv1=length_v(), nv2=sp2.length_v(); int nv=nv1; if(nv2>nv) nv=nv2; int i,j; const MGVector zero(0.,0.,0.); if(sd>sdim()){ MGSPointSeq sp(nu,nv,sd); for(i=0; isd) sd=sd2; int nu1=length_u(), nu2=sp2.length_u(); int nu=nu1; if(nu2>nu) nu=nu2; int nv1=length_v(), nv2=sp2.length_v(); int nv=nv1; if(nv2>nv) nv=nv2; int i,j; const MGVector zero(0.,0.,0.); if(sd>sdim()){ MGSPointSeq sp(nu,nv,sd); for(i=0; i