Welcome to mirror list, hosted at ThFree Co, Russian Federation.

DT_Facet.h « convex « src « solid « extern - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 873706346b86d3decfcbf9f4354cb051b07917da (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/*
 * SOLID - Software Library for Interference Detection
 * 
 * Copyright (C) 2001-2003  Dtecta.  All rights reserved.
 *
 * This library may be distributed under the terms of the Q Public License
 * (QPL) as defined by Trolltech AS of Norway and appearing in the file
 * LICENSE.QPL included in the packaging of this file.
 *
 * This library may be distributed and/or modified under the terms of the
 * GNU General Public License (GPL) version 2 as published by the Free Software
 * Foundation and appearing in the file LICENSE.GPL included in the
 * packaging of this file.
 *
 * This library is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 *
 * Commercial use or any other use of this library not covered by either 
 * the QPL or the GPL requires an additional license from Dtecta. 
 * Please contact info@dtecta.com for enquiries about the terms of commercial
 * use of this library.
 */

#ifndef DT_FACET_H
#define DT_FACET_H

#include <string.h>
#include <vector>

#include <MT_Vector3.h>
#include <MT_Point3.h>

class DT_Facet;


class DT_Edge {
public:
    DT_Edge() {}
    DT_Edge(DT_Facet *facet, int index) : 
	m_facet(facet), 
	m_index(index) {}

    DT_Facet *getFacet() const { return m_facet; }
    int       getIndex() const { return m_index; }

    int getSource() const;
    int getTarget() const;

private:    
    DT_Facet *m_facet;
    int       m_index;
};

typedef std::vector<DT_Edge> DT_EdgeBuffer;


class DT_Facet {
public:
    DT_Facet() {}
    DT_Facet(int i0, int i1, int i2) 
	  :	m_obsolete(false) 
    {
		m_indices[0] = i0; 
		m_indices[1] = i1; 
		m_indices[2] = i2;
    }
	
    int operator[](int i) const { return m_indices[i]; } 

    bool link(int edge0, DT_Facet *facet, int edge1);

    
    bool isObsolete() const { return m_obsolete; }
    

    bool computeClosest(const MT_Vector3 *verts);
    
    const MT_Vector3& getClosest() const { return m_closest; } 
    
    bool isClosestInternal() const
	{ 
		return m_lambda1 >= MT_Scalar(0.0) && 
			m_lambda2 >= MT_Scalar(0.0) && 
			m_lambda1 + m_lambda2 <= m_det;
    } 

    MT_Scalar getDist2() const { return m_dist2; }
	
    MT_Point3 getClosestPoint(const MT_Point3 *points) const 
	{
		const MT_Point3& p0 = points[m_indices[0]];
		
		return p0 + (m_lambda1 * (points[m_indices[1]] - p0) + 
					 m_lambda2 * (points[m_indices[2]] - p0)) / m_det;
    }
    
    void silhouette(const MT_Vector3& w, DT_EdgeBuffer& edgeBuffer) 
	{
		edgeBuffer.clear();
		m_obsolete = true;
		m_adjFacets[0]->silhouette(m_adjEdges[0], w, edgeBuffer);
		m_adjFacets[1]->silhouette(m_adjEdges[1], w, edgeBuffer);
		m_adjFacets[2]->silhouette(m_adjEdges[2], w, edgeBuffer);
    }
	
private:
    void silhouette(int index, const MT_Vector3& w, DT_EdgeBuffer& edgeBuffer);
	
    int         m_indices[3];
    bool        m_obsolete;
    DT_Facet   *m_adjFacets[3];
    int         m_adjEdges[3];
	
    MT_Scalar   m_det;
    MT_Scalar   m_lambda1;
    MT_Scalar   m_lambda2;
    MT_Vector3  m_closest;
    MT_Scalar   m_dist2;
};


inline int incMod3(int i) { return ++i % 3; } 

inline int DT_Edge::getSource() const 
{
    return (*m_facet)[m_index];
}

inline int DT_Edge::getTarget() const 
{
    return (*m_facet)[incMod3(m_index)];
}

#endif