コード例 #1
0
ファイル: surface_c2.py プロジェクト: jkotur/Torrusador
	def draw_debug_derivatives( self ) :
		v = 11.5
		glColor3f(1,0,0)
		glBegin(GL_LINES)
		p = csurf.bspline_surf        ( 0 , v , self.array_pts )
		dv= csurf.bspline_surf_prime_v( 0 , v , self.array_pts )
		du= csurf.bspline_surf_prime_u( 0 , v , self.array_pts )
		glVertex3f( p[0] , p[1] , p[2] )
		glVertex3f(*(p+dv) )
		glVertex3f( p[0] , p[1] , p[2] )
		glVertex3f(*(p+du) )
		glVertex3f( p[0] , p[1] , p[2] )
		for i in np.linspace(float(self.size[0])/64,self.size[0],64,False) :
			p = csurf.bspline_surf        ( i , v , self.array_pts )
			dv= csurf.bspline_surf_prime_v( i , v , self.array_pts )
			du= csurf.bspline_surf_prime_u( i , v , self.array_pts )
			glVertex3f( p[0] , p[1] , p[2] )
			glVertex3f( p[0] , p[1] , p[2] )
			glVertex3f(*(p+dv) )
			glVertex3f( p[0] , p[1] , p[2] )
			glVertex3f(*(p+du) )
			glVertex3f( p[0] , p[1] , p[2] )
		p = csurf.bspline_surf        ( self.size[0] , v , self.array_pts )
		dv= csurf.bspline_surf_prime_v( self.size[0] , v , self.array_pts )
		du= csurf.bspline_surf_prime_u( self.size[0] , v , self.array_pts )
		glVertex3f( p[0] , p[1] , p[2] )
		glVertex3f(*(p+dv) )
		glVertex3f( p[0] , p[1] , p[2] )
		glVertex3f(*(p+du) )
		glVertex3f( p[0] , p[1] , p[2] )
		glEnd()
		glColor3f(1,1,1,0)
コード例 #2
0
 def draw_debug_derivatives(self):
     v = 11.5
     glColor3f(1, 0, 0)
     glBegin(GL_LINES)
     p = csurf.bspline_surf(0, v, self.array_pts)
     dv = csurf.bspline_surf_prime_v(0, v, self.array_pts)
     du = csurf.bspline_surf_prime_u(0, v, self.array_pts)
     glVertex3f(p[0], p[1], p[2])
     glVertex3f(*(p + dv))
     glVertex3f(p[0], p[1], p[2])
     glVertex3f(*(p + du))
     glVertex3f(p[0], p[1], p[2])
     for i in np.linspace(
             float(self.size[0]) / 64, self.size[0], 64, False):
         p = csurf.bspline_surf(i, v, self.array_pts)
         dv = csurf.bspline_surf_prime_v(i, v, self.array_pts)
         du = csurf.bspline_surf_prime_u(i, v, self.array_pts)
         glVertex3f(p[0], p[1], p[2])
         glVertex3f(p[0], p[1], p[2])
         glVertex3f(*(p + dv))
         glVertex3f(p[0], p[1], p[2])
         glVertex3f(*(p + du))
         glVertex3f(p[0], p[1], p[2])
     p = csurf.bspline_surf(self.size[0], v, self.array_pts)
     dv = csurf.bspline_surf_prime_v(self.size[0], v, self.array_pts)
     du = csurf.bspline_surf_prime_u(self.size[0], v, self.array_pts)
     glVertex3f(p[0], p[1], p[2])
     glVertex3f(*(p + dv))
     glVertex3f(p[0], p[1], p[2])
     glVertex3f(*(p + du))
     glVertex3f(p[0], p[1], p[2])
     glEnd()
     glColor3f(1, 1, 1, 0)
コード例 #3
0
ファイル: cutter.py プロジェクト: jkotur/Torrusador
	def find_first_uv( self , uvuv ) :
		uvuv = csurf.cut_bsplines(
				self.tocut[0].get_array_pts() ,
				self.tocut[1].get_array_pts() , uvuv )

		self.tocut[0].trim_p0 = csurf.bspline_surf( uvuv[0], uvuv[1], self.tocut[0].array_pts )
		self.tocut[1].trim_p0 = csurf.bspline_surf( uvuv[2], uvuv[3], self.tocut[1].array_pts )

		print uvuv[:2] , self.tocut[0].trim_p0
		print uvuv[2:] , self.tocut[1].trim_p0

		return uvuv
コード例 #4
0
ファイル: cutter.py プロジェクト: jkotur/Torrusador
    def find_first_uv(self, uvuv):
        uvuv = csurf.cut_bsplines(self.tocut[0].get_array_pts(),
                                  self.tocut[1].get_array_pts(), uvuv)

        self.tocut[0].trim_p0 = csurf.bspline_surf(uvuv[0], uvuv[1],
                                                   self.tocut[0].array_pts)
        self.tocut[1].trim_p0 = csurf.bspline_surf(uvuv[2], uvuv[3],
                                                   self.tocut[1].array_pts)

        print uvuv[:2], self.tocut[0].trim_p0
        print uvuv[2:], self.tocut[1].trim_p0

        return uvuv
コード例 #5
0
ファイル: cutter.py プロジェクト: jkotur/Torrusador
    def find_trimming(self, uvuv, delta):
        maxuvuv = np.array((self.tocut[0].size[0], self.tocut[0].size[1],
                            self.tocut[1].size[0], self.tocut[1].size[1]))

        baseuvuv = uvuv

        self.tocut[0].begin_trimming_curve(delta)
        self.tocut[1].begin_trimming_curve(delta)

        self.tocut[0].append_trimming_uv(uvuv[0], uvuv[1])
        self.tocut[1].append_trimming_uv(uvuv[2], uvuv[3])

        trimming = [
            csurf.bspline_surf(uvuv[0], uvuv[1], self.tocut[0].array_pts)
        ]
        self.tocut[0].trimming_curve = trimming
        while all(uvuv < maxuvuv) and all(uvuv > np.zeros(4)):
            print 'Newton     (', uvuv, ')', '(', maxuvuv, ')'
            uvuv = csurf.next_cut_bsplines(self.tocut[0].get_array_pts(),
                                           self.tocut[1].get_array_pts(), uvuv,
                                           trimming[-1], delta)
            self.tocut[0].append_trimming_uv(uvuv[0], uvuv[1])
            self.tocut[1].append_trimming_uv(uvuv[2], uvuv[3])

            trimming.append(
                csurf.bspline_surf(uvuv[0], uvuv[1], self.tocut[0].array_pts))

        self._add_minmax(uvuv, maxuvuv)

        uvuv = baseuvuv
        while all(uvuv < maxuvuv) and all(uvuv > np.zeros(4)):
            print 'Newton rev (', uvuv, ')', '(', maxuvuv, ')'
            uvuv = csurf.next_cut_bsplines(self.tocut[0].get_array_pts(),
                                           self.tocut[1].get_array_pts(),
                                           uvuv,
                                           trimming[0],
                                           delta,
                                           inv=True)
            self.tocut[0].prepend_trimming_uv(uvuv[0], uvuv[1])
            self.tocut[1].prepend_trimming_uv(uvuv[2], uvuv[3])

            trimming.insert(
                0, csurf.bspline_surf(uvuv[0], uvuv[1],
                                      self.tocut[0].array_pts))

        self._add_minmax(uvuv, maxuvuv)

        A = self.tocut[0].end_trimming()
        B = self.tocut[1].end_trimming()

        return A, B
コード例 #6
0
    def gen_line_u(self, pts, path, r, v, bu, eu, nu):
        sys.stdout.write('.')
        sys.stdout.flush()

        odu = None
        cn = None  # current normal
        pn = None  # previous normal

        for iu in np.linspace(bu, eu, nu):

            p = csurf.bspline_surf(iu, v, pts)
            dv = csurf.bspline_surf_prime_v(iu, v, pts)
            du = csurf.bspline_surf_prime_u(iu, v, pts)
            n = np.cross(du, dv)
            nlen = np.linalg.norm(n)
            dlen = np.linalg.norm(du)
            ndu = du / dlen
            # paths count optimization
            if odu != None and np.allclose(ndu, odu, atol=0.001):
                continue
            if dlen > 0.01:
                n = n / nlen
                if cn == None and pn != None:  # C0 edge
                    cn = n
                    tn = (pn + cn)
                    tn = tn / np.linalg.norm(tn)
                    path.append(np.array(p + tn * r))
                else:  # normal is well defined
                    pn = cn
                    cn = n
                    path.append(np.array(p + cn * r))
            else:  # normal is undefined
                cn = None

            odu = ndu
コード例 #7
0
 def gen_bspline_point(self, u, v, r, pts):
     p = csurf.bspline_surf(u, v, pts)
     dv = csurf.bspline_surf_prime_v(u, v, pts)
     du = csurf.bspline_surf_prime_u(u, v, pts)
     n = np.cross(du, dv)
     n = n / np.linalg.norm(n)
     return p + n * r
コード例 #8
0
ファイル: milling_paths.py プロジェクト: jkotur/Torrusador
	def gen_bspline_point( self , u , v , r , pts ) :
		p = csurf.bspline_surf        ( u , v , pts )
		dv= csurf.bspline_surf_prime_v( u , v , pts )
		du= csurf.bspline_surf_prime_u( u , v , pts )
		n = np.cross( du , dv )
		n = n / np.linalg.norm( n )
		return p + n * r
コード例 #9
0
ファイル: milling_paths.py プロジェクト: jkotur/Torrusador
	def gen_line_u( self , pts , path , r , v , bu , eu , nu ) :
		sys.stdout.write('.')
		sys.stdout.flush()

		odu = None
		cn = None # current normal
		pn = None # previous normal

		for iu in np.linspace(bu,eu,nu) :

			p = csurf.bspline_surf        ( iu, v, pts )
			dv= csurf.bspline_surf_prime_v( iu, v, pts )
			du= csurf.bspline_surf_prime_u( iu, v, pts )
			n = np.cross( du , dv )
			nlen = np.linalg.norm( n )
			dlen = np.linalg.norm( du )
			ndu  = du / dlen
			# paths count optimization
			if odu != None and np.allclose(ndu,odu,atol=0.001) :
				continue
			if dlen > 0.01 :
				n = n / nlen
				if cn == None and pn != None : # C0 edge
					cn = n
					tn = (pn+cn)
					tn = tn / np.linalg.norm(tn)
					path.append( np.array( p + tn*r ) )
				else : # normal is well defined
					pn = cn
					cn = n
					path.append( np.array( p + cn * r ) )
			else : # normal is undefined
				cn = None

			odu = ndu
コード例 #10
0
    def gen_line_u_with_trimming(self, v, bu, eu, nu, z0, pts, trm, dtrm,
                                 path):
        sys.stdout.write('.')
        sys.stdout.flush()

        odu = None
        cn = None  # current normal
        pn = None  # previous normal

        for iu in np.linspace(bu, eu, nu):

            p = csurf.bspline_surf(iu, v, pts)
            dv = csurf.bspline_surf_prime_v(iu, v, pts)
            du = csurf.bspline_surf_prime_u(iu, v, pts)

            fi = 0
            while fi < len(trm) and not self.check_pass(
                    p, trm[fi], dtrm[fi][1]):
                fi += 1
            ri = len(trm) - 1
            while ri >= 0 and self.check_pass(p, trm[ri], dtrm[ri][1]):
                ri -= 1

#            if( fi<len(trm) and self.check_pass( p, trm[fi], dtrm[fi][0] )) \
#            and( ri>=0       and not self.check_pass( p, trm[ri], dtrm[ri][0] )) :
            if( fi<len(trm) and ri>=0 ) and \
              ((self.check_pass( p, trm[fi], dtrm[fi][0] )) or \
              ( self.check_pass( p, trm[ri], dtrm[ri][0] ))) :
                continue

#            if ri == -1 and fi == 0 : continue

#            if not self.check_pass( p , np.array((0,0,z0)) , np.array((0,0,-1)) ) :
#                continue

            n = np.cross(du, dv)
            nlen = np.linalg.norm(n)
            dlen = np.linalg.norm(du)
            ndu = du / dlen
            # paths count optimization
            if odu != None and np.allclose(ndu, odu, atol=0.001):
                continue
            if dlen > 0.01:
                n = n / nlen
                if cn == None and pn != None:  # C0 edge
                    cn = n
                    tn = (pn + cn)
                    tn = tn / np.linalg.norm(tn)
                    path.append(np.array(p + tn * self.exac_r))
                else:  # normal is well defined
                    pn = cn
                    cn = n
                    path.append(np.array(p + cn * self.exac_r))
            else:  # normal is undefined
                cn = None

            odu = ndu
コード例 #11
0
ファイル: cutter.py プロジェクト: jkotur/Torrusador
	def find_trimming( self , uvuv , delta ) :
		maxuvuv = np.array((self.tocut[0].size[0],self.tocut[0].size[1],self.tocut[1].size[0],self.tocut[1].size[1]))

		baseuvuv = uvuv

		self.tocut[0].begin_trimming_curve( delta )
		self.tocut[1].begin_trimming_curve( delta )

		self.tocut[0].append_trimming_uv( uvuv[0] , uvuv[1] )
		self.tocut[1].append_trimming_uv( uvuv[2] , uvuv[3] )

		trimming = [ csurf.bspline_surf( uvuv[0], uvuv[1], self.tocut[0].array_pts ) ]
		self.tocut[0].trimming_curve = trimming
		while all( uvuv < maxuvuv ) and all( uvuv > np.zeros(4) ) :
			print 'Newton     (' , uvuv , ')' , '(' , maxuvuv , ')'
			uvuv = csurf.next_cut_bsplines( 
				self.tocut[0].get_array_pts() ,
				self.tocut[1].get_array_pts() ,
				uvuv , trimming[-1] , delta )
			self.tocut[0].append_trimming_uv( uvuv[0] , uvuv[1] )
			self.tocut[1].append_trimming_uv( uvuv[2] , uvuv[3] )

			trimming.append( csurf.bspline_surf( uvuv[0], uvuv[1], self.tocut[0].array_pts ) )

		self._add_minmax( uvuv , maxuvuv )

		uvuv = baseuvuv
		while all( uvuv < maxuvuv ) and all( uvuv > np.zeros(4) ) :
			print 'Newton rev (' , uvuv , ')' , '(' , maxuvuv , ')'
			uvuv = csurf.next_cut_bsplines( 
				self.tocut[0].get_array_pts() ,
				self.tocut[1].get_array_pts() ,
				uvuv , trimming[0] , delta , inv = True )
			self.tocut[0].prepend_trimming_uv( uvuv[0] , uvuv[1] )
			self.tocut[1].prepend_trimming_uv( uvuv[2] , uvuv[3] )

			trimming.insert( 0 , csurf.bspline_surf( uvuv[0], uvuv[1], self.tocut[0].array_pts ) )

		self._add_minmax( uvuv , maxuvuv )

		A = self.tocut[0].end_trimming()
		B = self.tocut[1].end_trimming()

		return A , B
コード例 #12
0
ファイル: milling_paths.py プロジェクト: jkotur/Torrusador
	def gen_line_u_with_trimming( self , v , bu , eu , nu , z0 , pts , trm , dtrm , path ) :
		sys.stdout.write('.')
		sys.stdout.flush()

		odu = None
		cn = None # current normal
		pn = None # previous normal

		for iu in np.linspace(bu,eu,nu) :

			p = csurf.bspline_surf        ( iu, v, pts )
			dv= csurf.bspline_surf_prime_v( iu, v, pts )
			du= csurf.bspline_surf_prime_u( iu, v, pts )

			fi = 0
			while fi<len(trm) and not self.check_pass( p , trm[fi] , dtrm[fi][1] ) :
				fi+=1
			ri = len(trm)-1
			while ri>=0 and self.check_pass( p , trm[ri] , dtrm[ri][1] ) :
				ri-=1

#            if( fi<len(trm) and self.check_pass( p, trm[fi], dtrm[fi][0] )) \
#            and( ri>=0       and not self.check_pass( p, trm[ri], dtrm[ri][0] )) :
			if( fi<len(trm) and ri>=0 ) and \
			  ((self.check_pass( p, trm[fi], dtrm[fi][0] )) or \
			  ( self.check_pass( p, trm[ri], dtrm[ri][0] ))) :
				continue

#            if ri == -1 and fi == 0 : continue

#            if not self.check_pass( p , np.array((0,0,z0)) , np.array((0,0,-1)) ) :
#                continue

			n = np.cross( du , dv )
			nlen = np.linalg.norm( n )
			dlen = np.linalg.norm( du )
			ndu  = du / dlen
			# paths count optimization
			if odu != None and np.allclose(ndu,odu,atol=0.001) :
				continue
			if dlen > 0.01 :
				n = n / nlen
				if cn == None and pn != None : # C0 edge
					cn = n
					tn = (pn+cn)
					tn = tn / np.linalg.norm(tn)
					path.append( np.array( p + tn*self.exac_r ) )
				else : # normal is well defined
					pn = cn
					cn = n
					path.append( np.array( p + cn * self.exac_r ) )
			else : # normal is undefined
				cn = None

			odu = ndu
コード例 #13
0
ファイル: surface_c2.py プロジェクト: jkotur/Torrusador
	def make_add( self ) :
		arrpts = self.array_pts

#        print self.addind
		for k in range(len(self.addind)) :
			for i in range(len(self.addind[k])) :
#                print k , self.addpts.shape , len(self.addind)
				self.addpts[k][i,0,0] = self.bezy[ self.addind[k][i] *3    ]
				self.addpts[k][i,0,1] = self.bezy[ self.addind[k][i] *3 +1 ]
				self.addpts[k][i,0,2] = self.bezy[ self.addind[k][i] *3 +2 ]
				self.addpts[k][i,1] = csurf.bspline_surf( self.adduv[k][i][0], self.adduv[k][i][1], arrpts )
コード例 #14
0
    def find_trimming(self, r):
        u, v, head_pts = self.get_curve_data(self.head)
        u, v, hand_pts = self.get_curve_data(self.hand)

        head_trm = self.trm_uv_head
        hand_trm = self.trm_uv_hand

        bi = min(head_trm.minimal_v_id, head_trm.maximal_v_id)
        ei = max(head_trm.minimal_v_id, head_trm.maximal_v_id)
        nv = 32
        di = (ei - bi) / float(nv)

        path = []
        head_derv = []
        hand_derv = []

        fi = float(bi)
        while fi <= ei:
            i = int(fi)
            p = csurf.bspline_surf(head_trm.l[i][0], head_trm.l[i][1],
                                   head_pts)

            du = csurf.bspline_surf_prime_u(hand_trm.l[i][0], hand_trm.l[i][1],
                                            hand_pts)
            dv = csurf.bspline_surf_prime_v(hand_trm.l[i][0], hand_trm.l[i][1],
                                            hand_pts)
            hand_n = np.cross(du, dv)
            hand_n = hand_n / np.linalg.norm(hand_n)

            hand_derv.append((du, dv))

            du = csurf.bspline_surf_prime_u(head_trm.l[i][0], head_trm.l[i][1],
                                            head_pts)
            dv = csurf.bspline_surf_prime_v(head_trm.l[i][0], head_trm.l[i][1],
                                            head_pts)
            head_n = np.cross(du, dv)
            head_n = head_n / np.linalg.norm(head_n)

            head_derv.append((du, dv))

            n = head_n + hand_n
            n = n / np.linalg.norm(n)

            ln = m.sqrt(2) * r / m.sqrt(1 + np.dot(head_n, hand_n)) * 1.08

            path.append(p + n * ln)

            fi += di

        return path, head_derv, hand_derv
コード例 #15
0
    def make_add(self):
        arrpts = self.array_pts

        #        print self.addind
        for k in range(len(self.addind)):
            for i in range(len(self.addind[k])):
                #                print k , self.addpts.shape , len(self.addind)
                self.addpts[k][i, 0, 0] = self.bezy[self.addind[k][i] * 3]
                self.addpts[k][i, 0, 1] = self.bezy[self.addind[k][i] * 3 + 1]
                self.addpts[k][i, 0, 2] = self.bezy[self.addind[k][i] * 3 + 2]
                self.addpts[k][i,
                               1] = csurf.bspline_surf(self.adduv[k][i][0],
                                                       self.adduv[k][i][1],
                                                       arrpts)
コード例 #16
0
    def gen_border(self, r, z0, trm, tdhead, tdhand):
        path = []
        uhead, vhead, phead = self.get_curve_data(self.head)
        uhand, vhand, phand = self.get_curve_data(self.hand)

        nv = 128

        path.append(
            csurf.bspline_surf(6.0, vhead, phead) + np.array((-r, 0, 0)))

        for iv in np.linspace(vhead, 0, nv):
            path.append(self.gen_bspline_point(6.0, iv, r, phead))

        path.append(csurf.bspline_surf(6.0, 0, phead) + np.array((r, 0, 0)))
        path.append(csurf.bspline_surf(13.0, 0, phead) + np.array((r, 0, 0)))

        for iv in np.linspace(0, vhead, nv):
            p = self.gen_bspline_point(13.0, iv, r, phead)
            if self.check_pass(p, trm[-1], tdhead[-1][1]):
                #                path.append( trm[-1] )
                break
            path.append(p)

        for iv in np.linspace(vhand, 0, nv):
            p = self.gen_bspline_point(3.0, iv, r, phand)
            if self.check_pass(p, trm[-1], tdhand[-1][1]):
                continue
            path.append(np.array(p))

        path.append(csurf.bspline_surf(3.0, 0, phand) + np.array((0, -r, 0)))
        path.append(csurf.bspline_surf(7.0, 0, phand) + np.array((0, -r, 0)))

        for iv in np.linspace(0, vhand, nv):
            p = self.gen_bspline_point(7.0, iv, r, phand)
            if self.check_pass(p, trm[0], tdhand[0][1]):
                #                path.append( trm[0] )
                break
            path.append(p)

        for iv in np.linspace(0, vhead, nv):
            p = self.gen_bspline_point(13.0, iv, r, phead)
            if not self.check_pass(p, trm[0], tdhead[0][1]):
                continue
            path.append(p)

        path.append(
            csurf.bspline_surf(13.0, vhead, phead) + np.array((-r, 0, 0)))

        path.append(path[0])

        for v in path:
            v[2] = z0

        return path
コード例 #17
0
ファイル: milling_paths.py プロジェクト: jkotur/Torrusador
	def find_trimming( self , r ) :
		u , v , head_pts = self.get_curve_data( self.head )
		u , v , hand_pts = self.get_curve_data( self.hand )

		head_trm = self.trm_uv_head
		hand_trm = self.trm_uv_hand

		bi  = min( head_trm.minimal_v_id , head_trm.maximal_v_id )
		ei  = max( head_trm.minimal_v_id , head_trm.maximal_v_id )
		nv = 32
		di = (ei - bi) / float(nv)

		path = []
		head_derv = []
		hand_derv = []

		fi = float(bi)
		while fi <= ei :
			i = int(fi)
			p = csurf.bspline_surf( head_trm.l[i][0] , head_trm.l[i][1] , head_pts )

			du = csurf.bspline_surf_prime_u( hand_trm.l[i][0] , hand_trm.l[i][1] , hand_pts )
			dv = csurf.bspline_surf_prime_v( hand_trm.l[i][0] , hand_trm.l[i][1] , hand_pts )
			hand_n = np.cross( du , dv )
			hand_n = hand_n / np.linalg.norm( hand_n )

			hand_derv.append( (du,dv) )

			du = csurf.bspline_surf_prime_u( head_trm.l[i][0] , head_trm.l[i][1] , head_pts )
			dv = csurf.bspline_surf_prime_v( head_trm.l[i][0] , head_trm.l[i][1] , head_pts )
			head_n = np.cross( du , dv )
			head_n = head_n / np.linalg.norm( head_n )

			head_derv.append( (du,dv) )

			n = head_n + hand_n
			n = n / np.linalg.norm( n )

			ln = m.sqrt(2) * r / m.sqrt( 1 + np.dot( head_n , hand_n ) ) * 1.08

			path.append( p + n * ln )


			fi += di

		return path , head_derv , hand_derv
コード例 #18
0
ファイル: milling_paths.py プロジェクト: jkotur/Torrusador
	def gen_border( self , r , z0 , trm , tdhead , tdhand ) :
		path = []
		uhead , vhead , phead = self.get_curve_data( self.head )
		uhand , vhand , phand = self.get_curve_data( self.hand )

		nv = 128

		path.append( csurf.bspline_surf( 6.0, vhead , phead ) + np.array((-r,0,0)))

		for iv in np.linspace(vhead,0,nv) :
			path.append( self.gen_bspline_point( 6.0 , iv , r , phead ) )

		path.append( csurf.bspline_surf( 6.0, 0 , phead ) + np.array((r,0,0)))
		path.append( csurf.bspline_surf(13.0, 0 , phead ) + np.array((r,0,0)))

		for iv in np.linspace(0,vhead,nv) :
			p = self.gen_bspline_point( 13.0 , iv , r , phead )
			if self.check_pass( p , trm[-1] , tdhead[-1][1] ) :
#                path.append( trm[-1] )
				break
			path.append( p )

		for iv in np.linspace(vhand,0,nv) :
			p = self.gen_bspline_point( 3.0 , iv , r , phand )
			if self.check_pass( p , trm[-1] , tdhand[-1][1] ) :
				continue
			path.append( np.array( p ) )

		path.append( csurf.bspline_surf( 3.0, 0 , phand ) + np.array((0,-r,0)))
		path.append( csurf.bspline_surf( 7.0, 0 , phand ) + np.array((0,-r,0)))

		for iv in np.linspace(0,vhand,nv) :
			p = self.gen_bspline_point( 7.0 , iv , r , phand )
			if self.check_pass( p , trm[0] , tdhand[0][1] ) :
#                path.append( trm[0] )
				break
			path.append( p )

		for iv in np.linspace(0,vhead,nv) :
			p = self.gen_bspline_point( 13.0 , iv , r , phead )
			if not self.check_pass( p , trm[0] , tdhead[0][1] ) :
				continue
			path.append( p )

		path.append( csurf.bspline_surf(13.0, vhead , phead ) + np.array((-r,0,0)))

		path.append( path[0] )

		for v in path : v[2] = z0

		return path
コード例 #19
0
    def gen_exact(self, z0, trm, tdhead, tdhand):
        path_hand = []
        path_head = []

        #
        # hand
        #
        u, v, hand_pts = self.get_curve_data(self.hand)

        tn = np.cross(trm[-1] - trm[0], np.array((0, 0, 1)))
        tp = trm[0]

        bu = 3.0
        eu = 7.0
        nu = 64
        nv = 128
        dv = v / float(nv)
        iv = 0.0
        ev = iv

        while iv <= v:
            p = csurf.bspline_surf(eu, iv, hand_pts)
            if self.check_pass(p, tp, tn):
                self.gen_line_u_with_trimming(iv, bu, eu, nu, z0, hand_pts,
                                              trm, tdhand, path_hand)
                ev = iv
            iv += dv
            p = csurf.bspline_surf(eu, iv, hand_pts)
            if self.check_pass(p, tp, tn):
                self.gen_line_u_with_trimming(iv, eu, bu, nu, z0, hand_pts,
                                              trm, tdhand, path_hand)
                ev = iv
            iv += dv

        trmuv = self.trm_uv_hand.l
        i = 1
        for a in np.linspace(0, 1, 5):
            for uv in trmuv if not i % 2 else reversed(trmuv):
                if uv[0] > 3.0 and uv[0] < 7.0:
                    v = a * (uv[1] - 0.7) + (1 - a) * ev
                    p = csurf.bspline_surf(uv[0], v, hand_pts)
                    dv = csurf.bspline_surf_prime_v(uv[0], v, hand_pts)
                    du = csurf.bspline_surf_prime_u(uv[0], v, hand_pts)

                    n = np.cross(du, dv)
                    n = n / np.linalg.norm(n)

                    path_hand.append(np.array(p + n * self.exac_r))
            i += 1

        path_hand += trm

        #
        # head
        #
        u, v, head_pts = self.get_curve_data(self.head)

        bu = 6.0
        eu = 13.0
        nu = 64
        nv = 128
        dv = v / float(nv)
        iv = 0.0

        while iv <= v:
            self.gen_line_u_with_trimming(iv, bu, eu, nu, z0, head_pts, trm,
                                          tdhead, path_head)

            iv += dv

            self.gen_line_u_with_trimming(iv, eu, bu, nu, z0, head_pts, trm,
                                          tdhead, path_head)

            iv += dv

        print

        path = path_hand

        path.append(path_hand[-1] + np.array((0, 0, -1.2)))
        path.append(path_head[1] + np.array((0, 0, -1.2)))

        path += path_head

        # move from center to bottom
        for i in range(len(path)):
            path[i][2] += self.exac_r

        return np.array(path)
コード例 #20
0
ファイル: milling_paths.py プロジェクト: jkotur/Torrusador
	def gen_exact( self , z0 , trm , tdhead , tdhand ) :
		path_hand = []
		path_head = []

		#
		# hand
		#
		u , v , hand_pts = self.get_curve_data( self.hand )

		tn = np.cross( trm[-1] - trm[0] , np.array((0,0,1)) )
		tp = trm[0]

		bu = 3.0
		eu = 7.0
		nu = 64
		nv = 128
		dv = v / float(nv)
		iv = 0.0
		ev = iv

		while iv <= v :
			p = csurf.bspline_surf( eu , iv , hand_pts )
			if self.check_pass( p , tp , tn ) :
				self.gen_line_u_with_trimming( iv , bu , eu , nu , z0 , hand_pts , trm , tdhand , path_hand )
				ev = iv
			iv += dv
			p = csurf.bspline_surf( eu , iv , hand_pts )
			if self.check_pass( p , tp , tn ) :
				self.gen_line_u_with_trimming( iv , eu , bu , nu , z0 , hand_pts , trm , tdhand , path_hand )
				ev = iv
			iv += dv

		trmuv = self.trm_uv_hand.l
		i = 1
		for a in np.linspace(0,1,5) :
			for uv in trmuv if not i%2 else reversed(trmuv) :
				if uv[0] > 3.0 and uv[0] < 7.0 :
					v = a*(uv[1] - 0.7) + (1-a)*ev
					p = csurf.bspline_surf        ( uv[0] , v , hand_pts )
					dv= csurf.bspline_surf_prime_v( uv[0] , v , hand_pts )
					du= csurf.bspline_surf_prime_u( uv[0] , v , hand_pts )

					n = np.cross( du , dv )
					n = n / np.linalg.norm( n )

					path_hand.append( np.array( p + n * self.exac_r ) )
			i += 1

		path_hand += trm

		#
		# head
		#
		u , v , head_pts = self.get_curve_data( self.head )

		bu = 6.0
		eu = 13.0
		nu = 64
		nv = 128
		dv = v / float(nv)
		iv = 0.0

		while iv <= v :
			self.gen_line_u_with_trimming( iv , bu , eu , nu , z0 , head_pts , trm , tdhead , path_head )

			iv += dv

			self.gen_line_u_with_trimming( iv , eu , bu , nu , z0 , head_pts , trm , tdhead , path_head )

			iv += dv

		print 

		path = path_hand

		path.append( path_hand[-1] + np.array((0,0,-1.2)) )
		path.append( path_head[ 1] + np.array((0,0,-1.2)) )

		path += path_head

		# move from center to bottom
		for i in range(len(path)) : path[i][2] += self.exac_r

		return np.array( path )
コード例 #21
0
    def gen_initial(self, r, l, z):
        u, v, head_pts = self.get_curve_data(self.head)

        bu, eu = 7.0, 12.0
        bv, ev = 0, v

        pmin = csurf.bspline_surf(bu, 0, head_pts)
        pmax = csurf.bspline_surf(bu, v, head_pts)

        if pmin[0] > pmax[0]:
            pmin, pmax = pmax, pmin
            bv, ev = ev, bv

        bx, ex = BLOCK_X
        by, ey = BLOCK_Y

        path = []

        x = bx

        while x < ex:
            if x >= pmin[0] - r: break
            path.append(np.array((x, by, z)))
            path.append(np.array((x, ey, z)))
            x += r
            if x >= pmin[0] - r: break
            path.append(np.array((x, ey, z)))
            path.append(np.array((x, by, z)))
            x += r

        p = csurf.bspline_surf(bu, bv, head_pts)

        path[-2][0] = p[0] - self.init_r
        path[-1][0] = p[0] - self.init_r

        op = p = path[-1]

        nu = 64
        nv = 128
        iv = (ev - bv) / float(nv)
        v = bv
        s = m.copysign(1, ev - bv)

        while True:
            while s * v <= s * ev and p != None and m.fabs(p[0] - op[0]) < l:
                p = csurf.bspline_surf(eu, v, head_pts)
                dv = csurf.bspline_surf_prime_v(eu, v, head_pts)
                du = csurf.bspline_surf_prime_u(eu, v, head_pts)
                n = np.cross(du, dv)
                n = n / np.linalg.norm(n)
                p = p + n * r
                v += iv
            op = p

            if s * v > s * ev: break

            if v < 12 and v > 5:
                u1 = 8.0
                u2 = 11.0
            else:
                u1 = bu
                u2 = eu

            tp = []
            self.gen_line_u(head_pts, tp, r, v, u2, u1, nu)
            tp.insert(0, np.array((tp[0][0], by, tp[0][2])))
            tp.append(np.array((tp[-1][0], ey, tp[-1][2])))
            path += tp

            while s * v <= s * ev and p != None and m.fabs(p[0] - op[0]) < l:
                p = csurf.bspline_surf(bu, v, head_pts)
                dv = csurf.bspline_surf_prime_v(bu, v, head_pts)
                du = csurf.bspline_surf_prime_u(bu, v, head_pts)
                n = np.cross(du, dv)
                n = n / np.linalg.norm(n)
                p = p + n * r
                v += iv
            op = p

            if s * v > s * ev: break

            if v < 12 and v > 5:
                u1 = 8.0
                u2 = 11.0
            else:
                u1 = bu
                u2 = eu

            tp = []
            self.gen_line_u(head_pts, tp, r, v, u1, u2, nu)
            tp.insert(0, np.array((tp[0][0], ey, tp[0][2])))
            tp.append(np.array((tp[-1][0], by, tp[-1][2])))
            path += tp

        x = path[-1][0] + r

        while x < ex:
            path.append(np.array((x, ey, z)))
            path.append(np.array((x, by, z)))
            x += r
            path.append(np.array((x, by, z)))
            path.append(np.array((x, ey, z)))
            x += r

        # move from center to bottom
        for i in range(len(path)):
            path[i][2] += self.init_r

        return np.array(path)
コード例 #22
0
ファイル: milling_paths.py プロジェクト: jkotur/Torrusador
	def gen_initial( self , r , l , z ) :
		u , v , head_pts = self.get_curve_data( self.head )

		bu , eu = 7.0 , 12.0
		bv , ev = 0 , v

		pmin = csurf.bspline_surf( bu , 0 , head_pts )
		pmax = csurf.bspline_surf( bu , v , head_pts )

		if pmin[0] > pmax[0] :
			pmin , pmax = pmax , pmin
			bv   , ev   = ev   , bv

		bx , ex = BLOCK_X
		by , ey = BLOCK_Y

		path = []

		x = bx

		while x < ex :
			if x >= pmin[0] - r : break
			path.append( np.array((x,by,z)) )
			path.append( np.array((x,ey,z)) )
			x += r
			if x >= pmin[0] - r : break
			path.append( np.array((x,ey,z)) )
			path.append( np.array((x,by,z)) )
			x += r

		p = csurf.bspline_surf( bu , bv , head_pts )

		path[-2][0] = p[0] - self.init_r
		path[-1][0] = p[0] - self.init_r

		op = p = path[-1]

		nu = 64
		nv = 128
		iv = (ev-bv) / float(nv)
		v = bv
		s = m.copysign( 1 , ev - bv )

		while True :
			while s*v <= s*ev and p != None and m.fabs( p[0] - op[0] ) < l :
				p = csurf.bspline_surf( eu , v , head_pts )
				dv= csurf.bspline_surf_prime_v( eu , v , head_pts )
				du= csurf.bspline_surf_prime_u( eu , v , head_pts )
				n = np.cross( du , dv )
				n = n / np.linalg.norm( n )
				p = p + n * r
				v += iv
			op = p

			if s*v > s*ev : break


			if v < 12 and v > 5 :
				u1 = 8.0
				u2 = 11.0
			else :
				u1 = bu
				u2 = eu

			tp = []
			self.gen_line_u( head_pts , tp , r , v , u2 , u1 , nu )
			tp.insert( 0 , np.array((tp[0][0],by,tp[0][2])) )
			tp.append( np.array((tp[-1][0],ey,tp[-1][2])) )
			path += tp

			while s*v <= s*ev and p != None and m.fabs( p[0] - op[0] ) < l :
				p = csurf.bspline_surf( bu , v , head_pts )
				dv= csurf.bspline_surf_prime_v( bu , v , head_pts )
				du= csurf.bspline_surf_prime_u( bu , v , head_pts )
				n = np.cross( du , dv )
				n = n / np.linalg.norm( n )
				p = p + n * r
				v += iv
			op = p

			if s*v > s*ev : break

			if v < 12 and v > 5 :
				u1 = 8.0
				u2 = 11.0
			else :
				u1 = bu
				u2 = eu

			tp = []
			self.gen_line_u( head_pts , tp , r , v , u1 , u2 , nu )
			tp.insert( 0 , np.array((tp[0][0],ey,tp[0][2])) )
			tp.append( np.array((tp[-1][0],by,tp[-1][2])) )
			path += tp

		x = path[-1][0] + r

		while x < ex :
			path.append( np.array((x,ey,z)) )
			path.append( np.array((x,by,z)) )
			x += r 
			path.append( np.array((x,by,z)) )
			path.append( np.array((x,ey,z)) )
			x += r

		# move from center to bottom
		for i in range(len(path)) : path[i][2] += self.init_r

		return np.array( path )