Project

General

Profile

Download (6.28 KB) Statistics
| Branch: | Revision:

examples / src / main / java / org / distorted / examples / predeform / PredeformMeshList.java @ 641ea00c

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2020 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Distorted.                                                               //
5
//                                                                                               //
6
// Distorted is free software: you can redistribute it and/or modify                             //
7
// it under the terms of the GNU General Public License as published by                          //
8
// the Free Software Foundation, either version 2 of the License, or                             //
9
// (at your option) any later version.                                                           //
10
//                                                                                               //
11
// Distorted is distributed in the hope that it will be useful,                                  //
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of                                //
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                 //
14
// GNU General Public License for more details.                                                  //
15
//                                                                                               //
16
// You should have received a copy of the GNU General Public License                             //
17
// along with Distorted.  If not, see <http://www.gnu.org/licenses/>.                            //
18
///////////////////////////////////////////////////////////////////////////////////////////////////
19

    
20
package org.distorted.examples.predeform;
21

    
22
import org.distorted.library.mesh.MeshBase;
23
import org.distorted.library.mesh.MeshCubes;
24
import org.distorted.library.mesh.MeshQuad;
25
import org.distorted.library.mesh.MeshRectangles;
26
import org.distorted.library.mesh.MeshSphere;
27
import org.distorted.library.mesh.MeshTriangles;
28
import org.distorted.library.type.Static4D;
29

    
30
///////////////////////////////////////////////////////////////////////////////////////////////////
31

    
32
public enum PredeformMeshList
33
  {
34
  Cubes      ( 3 ),
35
  Rectangles ( 2 ),
36
  Sphere     ( 1 ),
37
  Quad       ( 0 ),
38
  Triangles  ( 1 ),
39
  ;
40

    
41
  static final int LENGTH = values().length;
42
  private static final PredeformMeshList[] meshes;
43
  private int mDimension;
44

    
45
  static
46
    {
47
    int i=0;
48
    meshes = new PredeformMeshList[LENGTH];
49

    
50
    for(PredeformMeshList mesh: PredeformMeshList.values())
51
      {
52
      meshes[i++] = mesh;
53
      }
54
    }
55

    
56
///////////////////////////////////////////////////////////////////////////////////////////////////
57

    
58
  PredeformMeshList(int dim )
59
    {
60
    mDimension =  dim;
61
    }
62

    
63
///////////////////////////////////////////////////////////////////////////////////////////////////
64

    
65
  static String getName(int ordinal)
66
    {
67
    return meshes[ordinal].name();
68
    }
69

    
70
///////////////////////////////////////////////////////////////////////////////////////////////////
71

    
72
  static int getDimension(int ordinal)
73
    {
74
    return  meshes[ordinal].mDimension;
75
    }
76

    
77
///////////////////////////////////////////////////////////////////////////////////////////////////
78

    
79
  static int getRows(int ordinal, int cols, int rows, int slic)
80
    {
81
    switch(ordinal)
82
      {
83
      case 0: return rows;  // cubes
84
      case 1: return rows;  // rectangles
85
      case 2: return rows;  // sphere
86
      case 3: return 1;     // quad
87
      case 4: return rows;  // triangles
88
      }
89

    
90
    return 0;
91
    }
92

    
93
///////////////////////////////////////////////////////////////////////////////////////////////////
94

    
95
  static int getCols(int ordinal, int cols, int rows, int slic)
96
    {
97
    switch(ordinal)
98
      {
99
      case 0: return cols;  // cubes
100
      case 1: return cols;  // rectangles
101
      case 2: return rows;  // sphere
102
      case 3: return 1;     // quad
103
      case 4: return rows;  // triangles
104
      }
105

    
106
    return 0;
107
    }
108

    
109
///////////////////////////////////////////////////////////////////////////////////////////////////
110

    
111
  static int getSlic(int ordinal, int cols, int rows, int slic)
112
    {
113
    switch(ordinal)
114
      {
115
      case 0: return slic;  // cubes
116
      case 1: return 0;     // rectangles
117
      case 2: return rows;  // sphere
118
      case 3: return 0;     // quad
119
      case 4: return 0;     // triangles
120
      }
121

    
122
    return 0;
123
    }
124

    
125
///////////////////////////////////////////////////////////////////////////////////////////////////
126

    
127
  static String getString(int ordinal, int cols, int rows, boolean[] shape)
128
    {
129
    if( ordinal==0 )
130
      {
131
      String str = "";
132

    
133
      for(int i=0; i<rows*cols; i++)
134
        str += shape[i] ? "1" : "0";
135

    
136
      return str;
137
      }
138

    
139
    return "";
140
    }
141

    
142
///////////////////////////////////////////////////////////////////////////////////////////////////
143

    
144
  static MeshBase createMesh(int ordinal, int cols, int rows, int slic, int bitmapID, String str)
145
    {
146
    MeshBase mesh;
147

    
148
    int maxsize = cols > rows ? (Math.max(cols, slic)) : (Math.max(rows, slic)) ;
149

    
150
    switch( meshes[ordinal] )
151
      {
152
      case Cubes     : if( bitmapID!=-1 )
153
                         {
154
                         mesh = new MeshCubes(cols, str, slic);
155
                         }
156
                       else
157
                         {
158
                         Static4D mapFB = new Static4D(0.0f,0.0f, (float)cols/maxsize, (float)rows/maxsize);
159
                         Static4D mapLR = new Static4D(0.0f,0.0f, (float)slic/maxsize, (float)rows/maxsize);
160
                         Static4D mapTB = new Static4D(0.0f,0.0f, (float)cols/maxsize, (float)slic/maxsize);
161

    
162
                         mesh = new MeshCubes(cols, str, slic, mapFB, mapFB, mapLR, mapLR, mapTB, mapTB);
163
                         }
164
                       break;
165
      case Rectangles: mesh = new MeshRectangles(cols,rows);
166
                       break;
167
      case Sphere    : mesh = new MeshSphere(rows);
168
                       break;
169
      case Quad      : mesh = new MeshQuad();
170
                       break;
171
      case Triangles : mesh = new MeshTriangles(rows);
172
                       break;
173
      default:         mesh = null;
174
                       android.util.Log.e("Meshes", "Error: unimplemented Mesh!");
175
      }
176

    
177
    return mesh;
178
    }
179
  }
(5-5/7)