Normand Briere
2019-09-02 0216409e390b2005d6bc4eaf564ef9ca2e508dab
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
import java.awt.Rectangle;
import java.util.Enumeration;
import java.util.Vector;
 
class Blob extends Composite implements java.io.Serializable
{
 
    Blob()
    {
        inPnt = new cVector();
        name = "Blob";
        threshold = 30;
        cellSize = 4;
        tolerance = 0; //.1;
    }
 
    Object3D deepCopy()
    {
        Blob blob = new Blob();
        deepCopySelf(blob);
        return blob;
    }
 
    protected void deepCopySelf(Object3D other)
    {
        super.deepCopySelf(other);
        Blob b = (Blob)other;
        b.threshold = threshold;
        b.cellSize = cellSize;
        b.tolerance = tolerance;
    }
 
    void generatePOV(StringBuffer buffer)
    {
        generateNameComment(buffer);
        generateIndent(buffer);
        buffer.append("blob { threshold ");
        buffer.append(threshold);
        buffer.append("\n");
        BlobComponent child;
        for (Enumeration e = children.elements(); e.hasMoreElements(); child.generatePOV(buffer))
            child = (BlobComponent)e.nextElement();
 
        generateTransform(buffer);
        generateIndent(buffer);
        buffer.append("}\n");
    }
 
    void createEditWindow(GroupEditor callee, boolean newWindow)
    {
        //editWindow = (new BlobEditor(this, deepCopy(), callee)).GetEditor();
       if (newWindow)
           objectUI = new BlobEditor(this, deepCopy(), callee);
       else
           objectUI = new BlobEditor(this, callee);
        editWindow = objectUI.GetEditor();
    }
 
    void draw(ClickInfo info, int level, boolean select)
    {
        drawSelf(info, level, select);
        if (level == 0 && (info.flags & 0x1) == 0)
            super.draw(info, level, select);
    }
 
   /*
   void draw000(javax.media.opengl.GL gl)
   {
       //drawSelf(gl);
        //if (level == 0 && (info.flags & 0x1) == 0)
            super.draw(gl);
   }
   */
   
    boolean doSelection(ClickInfo info, Rectangle r, int level)
    {
        if (level == 0 && (info.flags & 0x1) == 0)
            return super.doSelection(info, r, level);
        else
            return doSelectionSelf(info, r, level);
    }
 
    void retile()
    {
                new Exception().printStackTrace();
        System.exit(0);
       ClearList();
        bRep = (new ImplicitTiler(this, ImplicitTiler.SURFACEID, true, true, true, cellSize, cellSize, tolerance, true)).bRep;
    }
 
    public void getBounds(cVector minima, cVector maxima, boolean xform)
    {
        if (children.size() == 0)
        {
            minima.x = minima.y = minima.z = -1;
            maxima.x = maxima.y = maxima.z = 1;
            return;
        }
        
        super.getBounds(minima, maxima, xform);
        /*
        Enumeration e = children.elements();
        BlobComponent comp = (BlobComponent)e.nextElement();
   double radius = comp.radius * 1.1;
        for (int i=0; i < 3; i++)
        {
            minima.set(i, comp.center.get(i) - radius);
            maxima.set(i, comp.center.get(i) + radius);
        }
 
        while (e.hasMoreElements()) 
        {
            comp = (BlobComponent)e.nextElement();
       radius = comp.radius * 1.1;
            for (int i=0; i < 3; i++)
            {
                if (comp.center.get(i) - radius < minima.get(i))
                    minima.set(i, comp.center.get(i) - radius);
                if (comp.center.get(i) + radius > maxima.get(i))
                    maxima.set(i, comp.center.get(i) + radius);
            }
 
        }
        if (xform)
            transformBounds(minima, maxima);
         */
    }
 
    public boolean inside(double x, double y, double z, boolean xform)
    {
        //if (xform)
        //    untransform(x, y, z, inPnt);
        //else
        //    LA.setVector(inPnt, x, y, z);
        untransform(x, y, z, cStatic.point1);
        x = cStatic.point1.x;
        y = cStatic.point1.y;
        z = cStatic.point1.z;
        
        double total = 0;
        //for (Enumeration e = children.elements(); e.hasMoreElements();)
   for (int i=0; i<children.size(); i++)
        {
            //BlobComponent comp = (BlobComponent) children.reserve(i); // e.nextElement();
            Object3D comp = (Object3D) children.reserve(i); // e.nextElement();
            if (comp == null)
                continue;
            total += comp.getFieldStrength(x,y,z);
            children.release(i);
        }
 
        return total > threshold;
    }
 
    public void boxInside(double x[], double y[], double z[], boolean out[])
    {
        double range[] = new double[2];
        boxTotal(x, y, z, range);
        if (range[1] < threshold || range[0] > threshold)
            out[0] = out[1] = false;
        else
        if (x[1] - x[0] <= cellSize && y[1] - y[0] <= cellSize && z[1] - z[0] <= cellSize)
        {
            out[0] = out[1] = true;
        } else
        {
            out[0] = false;
            out[1] = true;
        }
    }
 
    private void boxTotal(double x[], double y[], double z[], double range[])
    {
        double contrib[] = new double[2];
        for (Enumeration e = children.elements(); e.hasMoreElements(); Interval.boxAdd(contrib, range, range))
        {
            BlobComponent comp = (BlobComponent)e.nextElement();
            comp.boxFieldStrength(x, y, z, contrib);
        }
 
    }
 
    double threshold;
    double cellSize;
    double tolerance;
    protected cVector inPnt;
}