/********************************************************************/ /* Copyright (c) 2017 System fugen G.K. and Yuzi Mizuno */ /* All rights reserved. */ /********************************************************************/ #include "MGCLStdAfx.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/Bvavpl.h" #if defined(_DEBUG) #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif // // Implementation of Class MGBpointSeq //Constructor MGBPointSeq::MGBPointSeq(int capacity, int dim) :m_capacity(capacity),m_sdim(dim),m_length(capacity){ int len=capacity*dim; if(len) m_bpoint=new double[len]; else{ m_sdim=m_capacity=m_length=0; m_bpoint=0; } } //Construct a MGBPointSeq by copying original MGBPointSeq. //Can change the order of coordinates MGBPointSeq::MGBPointSeq( int dim, // New Space Dimension. const MGBPointSeq& old_bpoint, // Origianl BPointSeq. int start1, // Destination start order to store. int start2 // Source start order to retrieve. ):m_capacity(old_bpoint.m_length),m_sdim(dim) , m_length(old_bpoint.m_length){ assert(start1=dim) j1=0; j2 +=1; if(j2>=dim2) j2=0; } while(k++=dim) j1=0; } }else m_bpoint=0; } // Construct by extracting sub interval of array2. MGBPointSeq::MGBPointSeq( int start_id, // Start id of bp_old int num, // New length(of new BPoint) const MGBPointSeq& bp_old // Origianl BPoint. ): m_capacity(num),m_sdim(bp_old.sdim()), m_length(num) , m_bpoint(new double[num*bp_old.sdim()]){ assert(start_id& poses) :m_capacity(0),m_sdim(0),m_length(0),m_bpoint(0){ int i, n=(int)poses.size(); if(!n) return; int sdmax=poses[0].sdim(); for(i=1; isdmax) sdmax=poses[i].sdim(); resize(n,sdmax); for(i=0; i=dataij ? dmax:dataij; dmin= dmin<=dataij ? dmin:dataij; } intrvl[j]=MGInterval(dmin,dmax); } MGBox ubox(dim, intrvl); delete[] intrvl; return ubox; } //Compute minimum box sorrounding the all the points. MGBox* MGBPointSeq::compute_box()const{ if(is_null()) return new MGBox(); int dim=sdim(); MGInterval* intrvl=new MGInterval[dim]; int len=length(); for(int j=0; j=dataij ? dmax:dataij; dmin= dmin<=dataij ? dmin:dataij; } intrvl[j]=MGInterval(dmin,dmax); } MGBox* ubox=new MGBox(dim, intrvl); delete[] intrvl; return ubox; } //Exchange ordering of the coordinates. //Exchange coordinates (j1) and (j2). void MGBPointSeq::coordinate_exchange(int j1, int j2){ assert(j1=ii; j--) for(m=0; m=dim2 ? dim1:dim2; double* v=new double[dim]; for(j=0; jdim1){ MGBPointSeq bnew(len, dim+1); for(i=0; i=dim2 ? dim1:dim2; int i,j; double a; int len=length(); if(dim>dim1){ MGBPointSeq bnew(len, dim+1); for(int k=0; k=ii; j--) for(m=0; mMGTolerance::wc_zero()) kplane=0; return kplane; } //Retrieve sub data of i-th point of the BPointSeq. //That is, P(k)=(*this)(i,j+k) for k=0, ..., sd-1. void MGBPointSeq::point(int i, int j, int sd, MGPosition& P)const{ P.resize(sd); int nd=sdim(); for(int k=0; k=nd) id-=nd; P(k)=ref(i,id); } } double MGBPointSeq::ref(int i, int j) const{ //Return (i,j)-th element data. // When j>=sdim(), return 0.0 . assert(i=sdim()) return 0.; else return m_bpoint[i+m_capacity*j]; } ///Change capacity. Change of sdim not allowed. ///reshape guarantees the original data BPoint(i,.) before invoking reshape ///will be stored in the new BPoint(start+i,.). ///reshape does not change the effective length, which must be set by set_length() ///if changed. void MGBPointSeq::reshape(int sz, int start){ if(sz==capacity() && start==0) return; int new_length=m_length+start; if(szsd2) len=sd2; for(int j=0; j=sd1) to=0; if(from>=sd2) from=0; m_bpoint[i+m_capacity*(to++)]=vector.ref(from++); } } //Store vector data vector(from+j) to this(i,to+j) for 0<=jsd1) len=sd1; for(int j=0; j=sd1) to=0; if(from>=sd2) from=0; m_bpoint[i+m_capacity*(to++)]=vector.ref(from++); } } //Store data[j] to this(i,to+j) for 0<=j=sd1) to=0; m_bpoint[i+m_capacity*(to++)]=data[j]; } } //Operator Definition //Extract (i,j) coordinate values for 0<=j=dim2 ? dim1:dim2; double* v=new double[dim]; for(j=0; jdim1){ MGBPointSeq bnew(len, dim); for(j=0; jsd) sd=sd2; int n=length(), n2=bp2.length(); int n1=n; if(n2>n) n=n2; if(sd>sdim()){ MGBPointSeq bp; if(n>n1){ bp=MGBPointSeq(sd, bp2); for(int i=0; i=dim2 ? dim1:dim2; int i,j; double a; int len=length(); if(dim>dim1){ MGBPointSeq bnew(len, dim); for(int k=0; ktotal_len) resize(len, dim); else{ m_sdim=dim; m_capacity=total_len/dim; } m_length=len; for(int j=0; jerror) return false; } return true; }