annotate mesh.h @ 15:d5758530a039 tip

oF0.84 Retina, and iPhone support
author Robert Tubb <rt300@eecs.qmul.ac.uk>
date Tue, 12 May 2015 15:48:52 +0100
parents 426d645d8e69
children
rev   line source
rt300@0 1 /*
rt300@0 2 * mesh.h
rt300@0 3 * springstructure
rt300@0 4 *
rt300@0 5 * Created by Robert Tubb on 07/06/2011.
rt300@0 6 * Copyright 2011 __MyCompanyName__. All rights reserved.
rt300@0 7 *
rt300@0 8 */
rt300@0 9
rt300@0 10 #ifndef _MESHH
rt300@0 11 #define _MESHH
rt300@0 12
rt300@0 13 #include <iostream>
rt300@0 14 #include "lump.h"
rt300@0 15 #include "scanpath.h"
rt300@0 16 #include "globalForces.h"
rt300@8 17 #include "json.h"
rt300@0 18
rt300@0 19 class Mesh{
rt300@0 20 public:
rt300@8 21 int dim1, dim2;
rt300@8 22
rt300@0 23 bool radial; // tells us if mesh is radial or not
rt300@0 24 // toggles
rt300@0 25 bool syrup;
rt300@0 26 bool home;
rt300@0 27
rt300@0 28 double propagationSpeed;
rt300@0 29
rt300@0 30 double k,m,f; // for stability check and asym
rt300@0 31
rt300@0 32 int numLumps;
rt300@0 33 int numSprings;
rt300@0 34
rt300@4 35 //Lump *lumps;
rt300@4 36 vector<Lump> lumps;
rt300@3 37 vector<Spring> springs;
rt300@3 38 //Spring *springs;
rt300@0 39
rt300@0 40 TwoVector centre;
rt300@0 41
rt300@0 42
rt300@0 43 // modes
rt300@0 44 enum constrainMode { CONSTRAIN_CORNERS, CONSTRAIN_EDGES,CONSTRAIN_EDGES_XY, CONSTRAIN_SINGLE_POINT, CONSTRAIN_SINGLE_POINT_X, CONSTRAIN_SINGLE_POINT_Y, CONSTRAIN_GRAB_REGION,CONSTRAIN_GRAB_REGION_X,CONSTRAIN_GRAB_REGION_Y, CONSTRAIN_ALL_X, CONSTRAIN_ALL_Y};
rt300@0 45 double GRAB_RANGE;
rt300@0 46
rt300@9 47 enum MeshType {SQUARE_MESH, SQUARE_CROSS_MESH, SPIDER_MESH, SPIDER_CROSS_MESH, DROPLET_MESH, LINE_MESH, TRIANGLE_MESH, GROUNDED_LINE_MESH, HOLED_SPIDER_MESH};
rt300@8 48 MeshType meshType;
rt300@0 49
rt300@0 50 // MEMBER FUNCTIONS
rt300@0 51 Mesh();
rt300@9 52 Mesh(Json::Value& savedMesh); // contructor using saved mesh
rt300@10 53 void setReasonableDefaults();
rt300@0 54 virtual ~Mesh();
rt300@0 55
rt300@0 56 void draw();
rt300@0 57
rt300@0 58 // INTERACTIONS
rt300@0 59 void resetAll();
rt300@0 60 void resetPositions();
rt300@0 61 void resetVelocities();
rt300@0 62 void resetEverything();
rt300@0 63
rt300@0 64 // excite via position, velocity force
rt300@0 65 // using shapes : noise, hamming, sine,
rt300@0 66 void hit(double dax,double day,int velocity = 100, GlobalForces::excitationTypes aEType = GlobalForces::POSITION,
rt300@0 67 GlobalForces::excitationShapes aEShape = GlobalForces::NOISE);
rt300@0 68 void spatialHarmonic(int aharm1 = 1, int aharm2 = 0);
rt300@0 69 void damp();
rt300@0 70 void forceField(double dax,double day,double strength);
rt300@0 71 void averagingFilter(double amt);
rt300@0 72
rt300@0 73 void grab(double x, double y, int touchID);
rt300@0 74 void drag(double ax,double ay, int touchID);
rt300@0 75 void unGrab(int touchID);
rt300@0 76
rt300@0 77 virtual void constrain(double x, double y, constrainMode aMode); // diff meshes will have diff edges
rt300@0 78 void unconstrain();
rt300@0 79 void unconstrain(double x, double y, constrainMode aMode);
rt300@0 80
rt300@0 81
rt300@0 82 // PARAMETER SETTINGS
rt300@0 83 void toggleSyrup();
rt300@0 84 void toggleSyrup(bool on);
rt300@0 85 void toggleSpringForces();
rt300@0 86 void toggleSpringForces(bool on);
rt300@0 87 void toggleGravity();
rt300@0 88 void toggleGravity(bool on);
rt300@0 89 void toggleHome(bool on);
rt300@0 90
rt300@0 91 void setRestLength();
rt300@0 92 void zeroRestLength();
rt300@0 93
rt300@0 94 void setPropagationSpeed(double aSpeed); // sets k and m to give a certain speed
rt300@0 95 void decreasePropagationSpeed();
rt300@0 96 void increasePropagationSpeed();
rt300@0 97 void setSpringConstant(double aK);
rt300@0 98 void setMass(double aM);
rt300@0 99 void setFriction(double aF);
rt300@0 100
rt300@0 101 // create varying constants
rt300@0 102 void setSpringConstantAsym(double aAsym);
rt300@0 103 void setMassAsym(double aAsym);
rt300@0 104 void setFrictionAsym(double aAsym);
rt300@0 105 void setZeroAudioLine();
rt300@0 106
rt300@0 107 // only for mouse cursor
rt300@0 108 void checkHover(double x, double y);
rt300@0 109
rt300@0 110 // SCANPATH STUFF
rt300@0 111 void clearScanPath();
rt300@0 112 void disconnectDraw(); // enables you to draw scanpths anywhere
rt300@0 113 int inscribeScanPath(double ax, double ay);
rt300@8 114
rt300@8 115 // inscribeScanPathFromJson
rt300@8 116
rt300@0 117 // called by scanpath.update wavetables
rt300@0 118 double getNextSample();
rt300@0 119
rt300@0 120 virtual void update();
rt300@8 121
rt300@8 122 // save stuff
rt300@8 123 Json::Value convertToJsonForSaving();
rt300@9 124 Json::Value saveConnectionsAsJson();
rt300@10 125 // UTILS
rt300@10 126 TwoVector calculateCentre();
rt300@10 127 void connect(int springnum,int lumpnum);
rt300@10 128 void connect(int springnum,int lumpnum,int alumpnum2);
rt300@10 129 int getNearestLump(double ax,double ay);
rt300@0 130 protected:
rt300@0 131
rt300@0 132 int prevLump;
rt300@0 133
rt300@0 134 // specific mesh shapes override these:
rt300@0 135
rt300@0 136 virtual void makeComponents(int adimension1, int adimension2);
rt300@0 137 virtual void setLumpPositions();
rt300@0 138 virtual void makeConnections();
rt300@0 139 virtual void makeDefaultScanPath();
rt300@9 140
rt300@9 141 // alternatively get from saved:
rt300@9 142
rt300@13 143 void setLumpPositionsFromJson(Json::Value lumpPositions, Json::Value lumpRestPositions);
rt300@9 144 void makeConnectionsFromJson(Json::Value connections);
rt300@9 145 void makeScanPathFromJson(Json::Value scanPathElements);
rt300@9 146 void constrainFromJson(Json::Value constrainedLumps);
rt300@10 147
rt300@0 148
rt300@0 149 };
rt300@0 150 //---------------------------------------------------------
rt300@0 151 class SpiderMesh : public Mesh{
rt300@0 152 public:
rt300@0 153 int numSpokes, numRings;
rt300@0 154
rt300@0 155 SpiderMesh(int aNumSpokes,int aNumRings);
rt300@0 156
rt300@0 157 virtual void constrain(double x, double y, constrainMode aMode);
rt300@0 158 virtual void makeComponents(int adimension1, int adimension2);
rt300@0 159 virtual void setLumpPositions();
rt300@0 160 virtual void makeConnections();
rt300@0 161 virtual void makeDefaultScanPath();
rt300@0 162 };
rt300@0 163 //---------------------------------------------------------
rt300@0 164 class HoledSpiderMesh : public Mesh{
rt300@0 165 public:
rt300@0 166 int numSpokes, numRings;
rt300@0 167
rt300@0 168 HoledSpiderMesh(int aNumSpokes,int aNumRings);
rt300@0 169 void constrain(double x, double y, constrainMode aMode);
rt300@0 170 void makeComponents(int adimension1, int adimension2);
rt300@0 171 void setLumpPositions();
rt300@0 172 void makeConnections();
rt300@0 173 void makeDefaultScanPath();
rt300@0 174 };
rt300@0 175 //---------------------------------------------------------
rt300@0 176 class SpiderCrossMesh : public Mesh{
rt300@0 177 public:
rt300@0 178 int numSpokes, numRings;
rt300@0 179
rt300@0 180 SpiderCrossMesh(int aNumSpokes,int aNumRings);
rt300@0 181
rt300@0 182 void constrain(double x, double y, constrainMode aMode);
rt300@0 183 void makeComponents(int adimension1, int adimension2); // override
rt300@0 184 void setLumpPositions(); // same
rt300@0 185 void makeConnections(); // overrride
rt300@0 186 void makeDefaultScanPath(); // same
rt300@0 187 };
rt300@0 188 //---------------------------------------------------------
rt300@9 189 // square grid
rt300@9 190 class SquareMesh : public Mesh{
rt300@0 191 public:
rt300@0 192 // square specific
rt300@0 193 int height;
rt300@0 194 int width;
rt300@9 195 SquareMesh();
rt300@9 196 SquareMesh(int height, int width);
rt300@9 197 ~SquareMesh();
rt300@9 198 void constrain(double x, double y, constrainMode aMode);
rt300@9 199 void makeComponents(int adimension1, int adimension2);
rt300@9 200 void setLumpPositions();
rt300@9 201 void makeConnections();
rt300@9 202 void makeDefaultScanPath();
rt300@9 203 };
rt300@9 204 //---------------------------------------------------------
rt300@9 205 // square grid with all diagonals connected i.e. we override makeConnections
rt300@9 206 class SquareCrossMesh : public SquareMesh{
rt300@9 207 public:
rt300@9 208 SquareCrossMesh(){};
rt300@9 209 SquareCrossMesh(int height, int width);
rt300@0 210 ~SquareCrossMesh();
rt300@0 211 void makeConnections();
rt300@9 212
rt300@0 213 };
rt300@0 214 //---------------------------------------------------------
rt300@0 215 // simple 1d line
rt300@0 216 class LineMesh : public Mesh{
rt300@0 217 public:
rt300@0 218 // square specific
rt300@0 219 int numSegments;
rt300@0 220
rt300@0 221 LineMesh(int aNumSegments);
rt300@0 222 void constrain(double x, double y, constrainMode aMode);
rt300@0 223 void makeComponents(int adimension1, int adimension2);
rt300@0 224 void setLumpPositions();
rt300@0 225 void makeConnections();
rt300@0 226 void makeDefaultScanPath();
rt300@0 227 };
rt300@0 228 //---------------------------------------------------------
rt300@0 229 // simple 1d line attached to 'ground' (constrained lumps) by other springs...
rt300@0 230 class GroundedLineMesh : public Mesh{
rt300@0 231 public:
rt300@0 232 int numSegments;
rt300@0 233
rt300@0 234 GroundedLineMesh(int aNumSegments);
rt300@0 235 void constrain(double x, double y, constrainMode aMode);
rt300@0 236 void makeComponents(int adimension1, int adimension2);
rt300@0 237 void setLumpPositions();
rt300@0 238 void makeConnections();
rt300@0 239 void makeDefaultScanPath();
rt300@0 240 };
rt300@0 241
rt300@0 242 //----------------------------------------------------------
rt300@0 243 //---------------------------------------------------------
rt300@0 244 // circular spring with internal pressure
rt300@0 245 class DropletMesh : public Mesh{
rt300@0 246 public:
rt300@0 247 // specific
rt300@0 248 int numSegments;
rt300@0 249 double restArea;
rt300@0 250
rt300@0 251 DropletMesh(int aNumSegments);
rt300@0 252 void constrain(double x, double y, constrainMode aMode);
rt300@0 253 void makeComponents(int adimension1, int adimension2);
rt300@0 254 void setLumpPositions();
rt300@0 255 void makeConnections();
rt300@0 256 void makeDefaultScanPath();
rt300@0 257 double calculatePressure();
rt300@0 258 double calculateArea();
rt300@0 259 void update();
rt300@0 260 };
rt300@0 261 //---------------------------------------------------------
rt300@0 262 // trangular mesh
rt300@0 263 class TriangleMesh : public Mesh{
rt300@0 264 public:
rt300@0 265 // square specific
rt300@0 266 int height;
rt300@0 267 int width;
rt300@0 268
rt300@0 269 TriangleMesh(int height, int width);
rt300@0 270 void constrain(double x, double y, constrainMode aMode);
rt300@0 271 void makeComponents(int adimension1, int adimension2);
rt300@0 272 void setLumpPositions();
rt300@0 273 void makeConnections();
rt300@0 274 void makeDefaultScanPath();
rt300@0 275 };
rt300@0 276 //----------------------------------------------------------
rt300@0 277
rt300@0 278 #endif