Exemple #1
0
    def testRemovedByRefFeature(self):
        ''' test that arguments returned by ref transormation is ok
        '''
        from OCC.BRepPrimAPI import BRepPrimAPI_MakeSphere
        from OCC.BRep import BRep_Tool_Surface
        from OCC.GeomLProp import GeomLProp_SLProps
        from OCC.gp import gp_Pnt
        sphere_shape = BRepPrimAPI_MakeSphere(40.).Shape()
        # build a surface from this sphere
        from OCC.Utils.Topology import Topo
        t = Topo(sphere_shape)
        for f in t.faces():
            face = f

        surf = BRep_Tool_Surface(face)
        lprop = GeomLProp_SLProps(0, 1e-12)
        lprop.SetSurface(surf)

        # evaluate_uv_coordinates
        coords = []
        p = 0.0
        # first point
        u, v = [0, 0]
        lprop.SetParameters(u, v)
        pnt = lprop.Value()
        print 'First point coords : ', pnt.Coord()
        print surf.GetObject().Value(u, v).Coord()
        # This one is [40.0,0.,0.]
        self.assertEqual(str(pnt.Coord()), '(40.0, 0.0, 0.0)')
        coords.append(pnt)
        #second point
        u, v = [0.5, 0.5]
        lprop.SetParameters(u, v)
        pnt2 = lprop.Value()
        # check then that the value has not changed (it does if returned by ref)
        self.assertEqual(str(pnt.Coord()), '(40.0, 0.0, 0.0)')
Exemple #2
0
class DiffGeomSurface(object):
    def __init__(self, instance):
        self.instance = instance
        self._curvature = None
        self._curvature_initiated = False

    def curvature(self, u, v):
        '''returns the curvature at the u parameter
        the curvature object can be returned too using
        curvatureType == curvatureType
        curvatureTypes are:
            gaussian
            minimum
            maximum
            mean
            curvatureType
        '''
        if not self._curvature_initiated:
            self._curvature = GeomLProp_SLProps(self.instance.surface_handle,
                                                u, v, 2, 1e-7)

        _domain = self.instance.domain()
        if u in _domain or v in _domain:
            print('<<<CORRECTING DOMAIN...>>>')
            div = 1000
            delta_u, delta_v = (_domain[0] - _domain[1]) / div, (
                _domain[2] - _domain[3]) / div

            if u in _domain:
                low, hi = u - _domain[0], u - _domain[1]
                if low < hi:
                    u = u - delta_u
                else:
                    u = u + delta_u

            if v in _domain:
                low, hi = v - _domain[2], v - _domain[3]
                if low < hi:
                    v = v - delta_v
                else:
                    v = v + delta_v

        self._curvature.SetParameters(u, v)
        self._curvature_initiated = True

        return self._curvature

    def gaussian_curvature(self, u, v):
        return self.curvature(u, v).GaussianCurvature()

    def min_curvature(self, u, v):
        return self.curvature(u, v).MinCurvature()

    def mean_curvature(self, u, v):
        return self.curvature(u, v).MeanCurvature()

    def max_curvature(self, u, v):
        return self.curvature(u, v).MaxCurvature()

    def normal(self, u, v):
        # TODO: should make this return a gp_Vec
        curv = self.curvature(u, v)
        if curv.IsNormalDefined():
            return curv.Normal()
        else:
            raise ValueError('normal is not defined at u,v: {0}, {1}'.format(
                u, v))

    def tangent(self, u, v):
        dU, dV = gp_Dir(), gp_Dir()
        curv = self.curvature(u, v)
        if curv.IsTangentUDefined() and curv.IsTangentVDefined():
            curv.TangentU(dU), curv.TangentV(dV)
            return dU, dV
        else:
            return None, None

    def radius(self, u, v):
        '''returns the radius at u
        '''
        # TODO: SHOULD WE RETURN A SIGNED RADIUS? ( get rid of abs() )?
        try:
            _crv_min = 1. / self.min_curvature(u, v)
        except ZeroDivisionError:
            _crv_min = 0.

        try:
            _crv_max = 1. / self.max_curvature(u, v)
        except ZeroDivisionError:
            _crv_max = 0.
        return abs((_crv_min + _crv_max) / 2.)
Exemple #3
0
class DiffGeomSurface(object):
    def __init__(self, instance):
        self.instance = instance
        self._curvature = None
        self._curvature_initiated = False

    def curvature(self, u,v):
        '''returns the curvature at the u parameter
        the curvature object can be returned too using curvatureType == curvatureType
        curvatureTypes are:
            gaussian
            minimum
            maximum
            mean
            curvatureType
        '''
        if not self._curvature_initiated:
            from OCC.GeomLProp import GeomLProp_SLProps
            self._curvature = GeomLProp_SLProps(self.instance.h_srf, u, v, 1, 1e-6)
        else:
            self._curvature.SetParameters(u,v)
            self._curvature_initiated = True

        return self._curvature

    def gaussian_curvature(self,u,v):
        return self.curvature(u,v).GaussianCurvature()

    def min_curvature(self,u,v):
        return self.curvature(u,v).MinCurvature()

    def mean_curvature(self,u,v):
        return self.curvature(u,v).MeanCurvature()

    def max_curvature(self,u,v):
        return self.curvature(u,v).MaxCurvature()

    def normal(self,u,v):
        # TODO: should make this return a gp_Vec
        curv = self.curvature(u,v)
        if curv.IsNormalDefined():
            return curv.Normal()
        else:
            raise ValueError('normal is not defined at u,v: {0}, {1}'.format(u,v))

    def tangent(self,u,v, recurse=False):
        dU, dV = gp_Dir(), gp_Dir()
        curv = self.curvature(u,v)
        if curv.IsCurvatureDefined():
            curv.TangentU(dU), curv.TangentV(dV)
            return dU, dV
        else:
            # most likely the curvature is just out of bounds...
            # move it a little close to the center of the surface...
            tol = 1e-2

            print 'trying to fix shit...'

            domain = self.instance.domain()
            if u in domain:
                uorv = 'u'
            elif v in domain:
                uorv = 'v'
            else:
                raise ValueError('no curvature defined while sample does not lie on border...')

            if uorv is not None:
                indx = domain.index(u) if uorv == 'u' else domain.index(v)
                if indx in (1,3): # v
                    v = v + tol if indx == 1 else v - tol
                else:
                    u = u + tol if indx == 0 else u - tol
                print 'hopefully fixed it?'
                if not recurse:
                    self.tangent(u,v, True)
                else:
                    return None

    def radius(self, u, v ):
        '''returns the radius at u
        '''
        # TODO: SHOULD WE RETURN A SIGNED RADIUS? ( get rid of abs() )?
        try:
            _crv_min = 1./self.min_curvature(u,v)
        except ZeroDivisionError:
            _crv_min = 0.

        try:
            _crv_max = 1./self.max_curvature(u,v)
        except ZeroDivisionError:
            _crv_max = 0.
        return abs((_crv_min+_crv_max)/2.)

    def frenet_frame(self, u, v):
        '''returns the frenet frame ( the 2 tangency directions + normal ) syntax sugar
        '''
        pass

    def derivative_u(self, u, n):
        '''return n derivatives of u
        '''
        pass

    def derivative_v(self, v, n):
        '''return n derivatives of v
        '''
        pass

    def torsion(self, u, v):
        '''returns the torsion at the parameter
        http://en.wikipedia.org/wiki/Frenet-Serret_formulas
        '''
        pass

    def continuity(self, face):
        '''returns continuity between self and another surface
        '''
        # add dictionary mapping which G / C continuity it is...
        return self.surface.Continuity()

    def inflection_parameters(self):
        """
        :return: a list of tuples (u,v) of parameters
        where there are inflection points on the edge

        returns None if no inflection parameters are found
        """
        pass
Exemple #4
0
class DiffGeomSurface(object):
    def __init__(self, instance):
        self.instance = instance
        self._curvature = None
        self._curvature_initiated = False

    def curvature(self, u, v):
        '''returns the curvature at the u parameter
        the curvature object can be returned too using curvatureType == curvatureType
        curvatureTypes are:
            gaussian
            minimum
            maximum
            mean
            curvatureType
        '''
        if not self._curvature_initiated:
            self._curvature = GeomLProp_SLProps(self.instance.surface_handle,
                                                u, v, 1, 1e-6)

        _domain = self.instance.domain()
        if u in _domain or v in _domain:
            print '<<<CORRECTING DOMAIN...>>>'
            div = 1000
            delta_u, delta_v = (_domain[0] - _domain[1]) / div, (
                _domain[2] - _domain[3]) / div

            if u in _domain:
                low, hi = u - _domain[0], u - _domain[1]
                if low < hi:
                    u = u - delta_u
                else:
                    u = u + delta_u

            if v in _domain:
                low, hi = v - _domain[2], v - _domain[3]
                if low < hi:
                    v = v - delta_v
                else:
                    v = v + delta_v

        self._curvature.SetParameters(u, v)
        self._curvature_initiated = True

        return self._curvature

    def gaussian_curvature(self, u, v):
        return self.curvature(u, v).GaussianCurvature()

    def min_curvature(self, u, v):
        return self.curvature(u, v).MinCurvature()

    def mean_curvature(self, u, v):
        return self.curvature(u, v).MeanCurvature()

    def max_curvature(self, u, v):
        return self.curvature(u, v).MaxCurvature()

    def normal(self, u, v):
        # TODO: should make this return a gp_Vec
        curv = self.curvature(u, v)
        if curv.IsNormalDefined():
            return curv.Normal()
        else:
            raise ValueError('normal is not defined at u,v: {0}, {1}'.format(
                u, v))

    def tangent(self, u, v):
        dU, dV = gp_Dir(), gp_Dir()
        curv = self.curvature(u, v)
        if curv.IsTangentUDefined() and curv.IsTangentVDefined():
            curv.TangentU(dU), curv.TangentV(dV)
            return dU, dV
        else:
            return None, None

    def radius(self, u, v):
        '''returns the radius at u
        '''
        # TODO: SHOULD WE RETURN A SIGNED RADIUS? ( get rid of abs() )?
        try:
            _crv_min = 1. / self.min_curvature(u, v)
        except ZeroDivisionError:
            _crv_min = 0.

        try:
            _crv_max = 1. / self.max_curvature(u, v)
        except ZeroDivisionError:
            _crv_max = 0.
        return abs((_crv_min + _crv_max) / 2.)

    def frenet_frame(self, u, v):
        '''returns the frenet frame ( the 2 tangency directions + normal ) syntax sugar
        '''
        pass

    def derivative_u(self, u, n):
        '''return n derivatives of u
        '''
        pass

    def derivative_v(self, v, n):
        '''return n derivatives of v
        '''
        pass

    def torsion(self, u, v):
        '''returns the torsion at the parameter
        http://en.wikipedia.org/wiki/Frenet-Serret_formulas
        '''
        pass

    def continuity(self, face):
        '''returns continuity between self and another surface
        '''
        # add dictionary mapping which G / C continuity it is...
        return self.surface.Continuity()

    def inflection_parameters(self):
        """
        :return: a list of tuples (u,v) of parameters
        where there are inflection points on the edge

        returns None if no inflection parameters are found
        """
        pass