Normand Briere
2019-11-07 f868664f7e7626f651e6ade9c9f6863851ef43b7
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
//import java.util.Vector;
 
abstract class Biparam extends Object3D implements java.io.Serializable
{
    static final long serialVersionUID = 6172913067490775416L;
 
    abstract Vertex biparamFunction(double f, double f1);
 
    Biparam()
    {
        name = "Biparam";
        endcaps = false;
       bRep = new BoundaryRep();
                
        mode = 0;
        CreateMaterial();
    }
 
    void DrawNode(iCameraPane display, Object3D /*Composite*/ root, boolean selected)
    {
        //System.out.println("#vertices = " + bRep.VertexCount());
        if(false)
        for(int i=0; i<bRep.VertexCount(); i++)
        {
            Vertex v = bRep.GetVertex(i);
            double x = v.x;
            double y = v.y;
            double z = v.z;
            int G = 65536;
            x = Math.floor(x*G)/G;
            y = Math.floor(y*G)/G;
            z = Math.floor(z*G)/G;
            cStatic.random.setSeed(Double.doubleToLongBits(x) ^ Double.doubleToLongBits(y) ^ Double.doubleToLongBits(z));
            v.x += (cStatic.random.nextFloat() - 0.5) * 0.1;
            v.y += (cStatic.random.nextFloat() - 0.5) * 0.1;
            v.z += (cStatic.random.nextFloat() - 0.5) * 0.1;
            bRep.SetVertex(v, i);
        }
        
        if (reset)
        {
            this.recalculate();
            reset = false;
        }
        
        super.DrawNode(display, root, selected);
    }
    
    protected void deepCopyNode(Object3D other)
    {
        super.deepCopyNode(other);
        Biparam bp = (Biparam)other;
        bp.uDivs = uDivs;
        bp.vDivs = vDivs;
        bp.endcaps = endcaps;
    }
 
    transient boolean touched = false;
    
    void retile()
    {
       //System.out.println("BREP TRIMMED? 1 " + bRep.trimmed);
       ClearList();
        if (endcaps)
            bRep.redimension((uDivs + 1) * (vDivs + 1) + (uDivs + 1) * 2 + 2, uDivs * (vDivs + 1) * 2);
        else
            bRep.redimension((uDivs + 1) * (vDivs + 1), uDivs * vDivs * 2);
        int ix = 0;
        for (int u = 0; u < uDivs; u++)
        {
            for (int v = 0; v < vDivs; v++)
            {
                int p = u * (vDivs + 1) + v;
                int q = p + 1;
                int r = p + vDivs + 1;
                int s = r + 1;
                if ((u+v)%2 == 1)
                {
                    bRep.setFace(ix++, p, s, q);
                    bRep.setFace(ix++, p, r, s);
                }
                else
                {
                    bRep.setFace(ix++, p, r, q);
                    bRep.setFace(ix++, r, s, q);
                }
            }
 
            if (endcaps)
            {
                int p = (uDivs + 1) * (vDivs + 1) + u;
                int q = p + 1;
                int r = (uDivs + 1) * (vDivs + 1) + (uDivs + 1) * 2;
                bRep.setFace(ix++, p, r, q);
                p += uDivs + 1;
                q = p + 1;
                r++;
                bRep.setFace(ix++, p, q, r);
            }
        }
       //System.out.println("BREP TRIMMED? 2 " + bRep.trimmed);
        
        touched = true;
//        recalculate();
    }
 
    double uStretch()
    {
        return 1;
    }
    
    double vFlip(double v)
    {
        return v;
    }
    
    void recalculate()
    {
       //System.out.println("BREP TRIMMED? 3 " + bRep.trimmed);
        double du = (double)uDivs;
        double dv = (double)vDivs;
        double u = 0;
        for (int iu = 0; iu < uDivs + 1; iu++)
        {
            u = iu/du;
            double v = 0;
            for (int iv = 0; iv < vDivs + 1; iv++)
            {
               v = iv/dv;
                Vertex vert = biparamFunction(u, v);
                int p = iu * (vDivs + 1) + iv;
                if (touched)
                {
                    vert.s = u * uStretch();
                    vert.t = vFlip(v);
                }
                else
                {
                    Vertex old = bRep.GetVertex(p);
                    vert.s = old.s;
                    vert.t = old.t;
                }
                //bRep.vertices.setElementAt(vert, p);
                bRep.SetVertex(vert, p);
                v += dv;
            }
 
            if (endcaps)
            {
                int p = iu * (vDivs + 1);
                int q = (uDivs + 1) * (vDivs + 1) + iu;
                //Vertex vert = (Vertex)bRep.vertices.elementAt(p);
                Vertex vert = bRep.GetVertex(p);
                //bRep.vertices.setElementAt(vert, q);
                bRep.SetVertex(vert, q);
                p += vDivs;
                q += uDivs + 1;
                //vert = (Vertex)bRep.vertices.elementAt(p);
                //bRep.vertices.setElementAt(vert, q);
                vert = bRep.GetVertex(p);
                bRep.SetVertex(vert, q);
            }
            u += du;
        }
 
        if (endcaps)
        {
            Vertex vert = biparamFunction(-1, 0);
 
            int p = (uDivs + 1) * (vDivs + 1) + (uDivs + 1) * 2;
            
            if (touched)
            {
                vert.s = -1;
                vert.t = 0;
            }
            else
            {
                Vertex old = bRep.GetVertex(p);
                vert.s = old.s;
                vert.t = old.t;
            }
            bRep.SetVertex(vert, p);
            vert = biparamFunction(-1, 1);
            p++;
            if (touched)
            {
                vert.s = -1;
                vert.t = 1;
            }
            else
            {
                Vertex old = bRep.GetVertex(p);
                vert.s = old.s;
                vert.t = old.t;
            }
            bRep.SetVertex(vert, p);
        }
       
        touched = false;
        
       super.recalculate();
                
       //System.out.println("BREP TRIMMED? 4 " + bRep.trimmed);
   //    if (!bRep.trimmed)
   //        bRep.Trim(cJME.trim, false, false, mode != 0, false);
    }
 
    int uDivs;
    int vDivs;
    int minUDivs;
    int minVDivs;
    boolean endcaps;
}