We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi everyone,
I repost this thread from the category "questions about code", hoping that this category is more relevant for my question
The code i paste does this:
there is the class TerrPt that creates a 3D array of points and then this class runs through the class agent (there are other functions also not pasted here)
my question is how i can check wich points of the 3D array TerrPt are inside and outside the mesh and exclude the ones inside .
the mesh is created in the main tab, in setup and draw, do you think that it needs to be initiated as a class itself?
thank you in advance! Stratis
import peasy.*;
import processing.opengl.*;
import peasy.org.apache.commons.math.*;
import peasy.*;
import peasy.org.apache.commons.math.geometry.*;
import toxi.geom.*;
import toxi.geom.mesh.*;
import toxi.processing.*;
import controlP5.*;
import toxi.math.noise.*;
import toxi.volume.*;
import toxi.math.*;
import toxi.geom.mesh.*;
PeasyCam cam;
int resX = 40;
int resY = 40;
int resZ = 10;
float gridSize = 10;
ArrayList <Agent> arrayOfAgents;
int ptCount = 0;
TerrPt [][][] terrain = new TerrPt[resX][resY][resZ];
ArrayList swarm;
//IsoSurface classes
VolumetricSpaceArray volume;
ArrayIsoSurface surface;
VolumetricBrush brush;
TriangleMesh mesh = new TriangleMesh("mesh");
ToxiclibsSupport gfx;
float ISO_THRESHOLD = 0.1;
float NS=0.03;
float ISO = 1f;
int GRID = 70;
int DIM = 240;
Vec3D SCALE = new Vec3D(DIM*1.5,DIM*1.5,DIM/2);
void setup() {
size(1600,920,P3D);
cam = new PeasyCam(this, 100,100,100,100);
cam.setMinimumDistance(200);
cam.setMaximumDistance(3500);
//INITIATE iso CLASSES
volume = new VolumetricSpaceArray(SCALE, GRID, GRID, GRID);
surface = new ArrayIsoSurface(volume);
brush = new RoundBrush(volume,SCALE.x/2);
gfx = new ToxiclibsSupport(this);
for(int i = 0; i < resX; i++) {
for (int j = 0; j < resY; j++) {
for (int k = 0; k < resZ; k++){
Vec3D ptLoc = new Vec3D(i * gridSize,j * gridSize, k * gridSize );
terrain [i][j][k] = new TerrPt(ptLoc,i,j,k,ptCount);
ptCount++;
}
}
}
}
void draw() {
background(255);
lights();
smooth();
volume.clear();
for(int i = 0; i < resX; i++) {
for (int j = 0; j < resY; j++) {
for (int k = 0; k < resZ; k++){
terrain [i][j][k].run();
}
}
}
volume.closeSides();
surface.reset();
surface.computeSurfaceMesh(mesh, ISO);
noStroke();
fill(255);
gfx.mesh(mesh, true);
//MESH TO CHECK INCLUSION WITH
//////////////////////////////////////////////////////////
pushMatrix();
translate(200,200,50);
float[] volumeData=volume.getData();
// fill volume with noise
for(int z=0,index=0; z<GRID; z++) {
for(int y=0; y<GRID; y++) {
for(int x=0; x<GRID; x++) {
volumeData[index++]=(float)SimplexNoise.noise(x*NS,y*NS,z*NS,0)*0.5;
}
}
}
long t0=System.nanoTime();
// store in IsoSurface and compute surface mesh for the given threshold value
surface.reset();
mesh=(TriangleMesh)surface.computeSurfaceMesh(mesh, ISO_THRESHOLD);
float timeTaken=(System.nanoTime()-t0)*1e-6;
volume.closeSides();
surface.reset();
surface.computeSurfaceMesh(mesh, ISO);
mesh=(TriangleMesh)surface.computeSurfaceMesh(mesh, ISO_THRESHOLD);
noStroke();
//stroke(0);
//strokeWeight(1);
fill(255);
gfx.mesh(mesh, true);
stroke(200);
fill(255,50);
popMatrix();
}
class Agent {
VolumetricBrush myBrush;
Vec3D loc;
void run() {
terr();
}
void terr() {
for (int i = 0; i < resX; i++) {
for (int j = 0; j < resY; j++) {
for (int k = 0; k < resZ; k++){
Vec3D ptLoc = new Vec3D(terrain[i][j][k].loc.x,terrain[i][j][k].loc.y,terrain[i][j][k].loc.z);
}
}
}
}
}
class TerrPt {
Vec3D loc;
int x;
int y;
int z;
int id;
float phe = 0;
int type = 0;
TerrPt(Vec3D _loc, int _x, int _y, int _z, int _id) {
loc = _loc;
x = _x;
y = _y;
z = _z;
id = _id;
}
void run() {
display();
}
void display() {
strokeWeight(1);
stroke(70,0,255);
point(loc.x,loc.y, loc.z);
}
}