📄 buttonspanel.java
字号:
} else if ( label.equals("IDC_CREATE_PLANE") ) { InfinitePlane plane; plane = new InfinitePlane(new Vector3D(-0.2, 0, 1), new Vector3D(0, 0, -1)); System.out.println(plane); parent.theScene.addThing(plane);/* parent.theScene.activeCamera.updateVectors(); InfinitePlane planes[]; planes = parent.theScene.activeCamera.getBoundingPlanes(); for ( int i = 0; i < 6; i++ ) { parent.theScene.addThing(planes[i]); }*/ } else if ( label.equals("IDC_CREATE_SPHERE_HARMONIC") ) { SimpleBody voxelBody = null; int selectedThing = parent.theScene.selectedThings.firstSelected(); Geometry referenceGeometry = null; if ( selectedThing >= 0 ) { voxelBody = parent.theScene.scene.getSimpleBodies().get(selectedThing); referenceGeometry = voxelBody.getGeometry(); } if ( referenceGeometry == null || !(referenceGeometry instanceof VoxelVolume) ) { parent.statusMessage.setText("ERROR: A VoxelVolume must be selected for spherical harmonic debugging sphere to be created"); } else { //- Calculate the VoxelVolume's center of mass --------------- VoxelVolume vv = (VoxelVolume)referenceGeometry; Vector3D cm = vv.doCenterOfMass(); //- Calculate average distance from nonzero voxels to cm ----- // This accounts for scale normalization as in [FUNK2003].4.1. int numberOfNonZeroVoxels = 0; double d; // Distance between a given voxel and center of mass Vector3D p; // Position of voxel double averageDistance = 0; int x, y, z; for ( x = 0; x < vv.getXSize(); x++ ) { for ( y = 0; y < vv.getYSize(); y++ ) { for ( z = 0; z < vv.getZSize(); z++ ) { if ( vv.getVoxel(x, y, z) != 0 ) { p = vv.getVoxelPosition(x, y, z); averageDistance += VSDK.vectorDistance(cm, p); numberOfNonZeroVoxels++; } } } } averageDistance /= (double)numberOfNonZeroVoxels; //- Create spheres ------------------------------------------- SimpleBody body; SimpleBodyGroup group = new SimpleBodyGroup(); int i; for ( i = 0; i < 32; i++ ) { body = addDebugSphere(voxelBody, i, cm, averageDistance); group.getBodies().add(body); } parent.theScene.debugThingGroups.add(group); // Subspheres account for translation & scale group.setRotation(voxelBody.getRotation()); } } else if ( label.equals("IDC_CREATE_PROJECTED_VIEWS") ) { parent.drawingArea.wantToDebugProjectedViews = true; } else if ( label.equals("IDC_CREATE_VOLUME") ) { //- Select current object, if empty selection take a temp. sphere - int selectedThing = parent.theScene.selectedThings.firstSelected(); Geometry referenceGeometry = null; SimpleBody thing = null; if ( selectedThing < 0 ) { referenceGeometry = new Sphere(0.5); } else { thing = parent.theScene.scene.getSimpleBodies().get(selectedThing); referenceGeometry = thing.getGeometry(); } //- Calculate transform matrix ------------------------------------ double minmax[] = referenceGeometry.getMinMax(); Matrix4x4 M; // Transform from voxelspace to geometry minmax space M = VoxelVolume.getTransformFromVoxelFrameToMinMax(minmax); //- Auxiliary variables ------------------------------------------- int nx = 64, ny = 64, nz = 64; //- Primitive rasterization --------------------------------------- VoxelVolume vv = new VoxelVolume(); vv.init(nx, ny, nz); ProgressMonitorConsole reporter = new ProgressMonitorConsole(); referenceGeometry.doVoxelization(vv, M, reporter); //- Append newly created volume to scene, matching reference form - SimpleBody newThing = parent.theScene.addThing(vv); Vector3D pos = new Vector3D(M.M[0][3], M.M[1][3], M.M[2][3]); if ( thing != null ) { pos = pos.add(thing.getPosition()); newThing.setRotation(thing.getRotation()); newThing.setScale(thing.getScale()); } newThing.setPosition(pos); Vector3D size = new Vector3D(M.M[0][0], M.M[1][1], M.M[2][2]); newThing.setScale(size); } else if ( label.equals("IDC_CREATE_BREP") ) { PolyhedralBoundedSolid brep; brep = (new Box(0.9, 0.9, 0.9)).exportToPolyhedralBoundedSolid(); Matrix4x4 R = new Matrix4x4(); R.translation(0.55, 0.55, 0.55); brep.applyTransformation(R); //- Cube modification to holed box ---------------------------- brep.smev(6, 5, 9, new Vector3D(0.3, 0.3, 1)); brep.kemr(6, 6, 5, 9, 9, 5); brep.smev(6, 9, 10, new Vector3D(0.8, 0.3, 1)); brep.smev(6, 10, 11, new Vector3D(0.8, 0.8, 1)); brep.smev(6, 11, 12, new Vector3D(0.3, 0.8, 1)); brep.mef(6, 6, 9, 10, 12, 11, 7); //- Box extrusion --------------------------------------------- brep.smev(7, 9, 13, new Vector3D(0.3, 0.3, 0.1)); brep.smev(7, 10, 14, new Vector3D(0.8, 0.3, 0.1)); brep.mef(7, 7, 13, 9, 14, 10, 8); brep.smev(7, 11, 15, new Vector3D(0.8, 0.8, 0.1)); brep.mef(7, 7, 14, 10, 15, 11, 9); brep.smev(7, 12, 16, new Vector3D(0.3, 0.8, 0.1)); brep.mef(7, 7, 15, 11, 16, 12, 10); brep.mef(7, 7, 13, 14, 16, 12, 11); //- Hole creation --------------------------------------------- brep.kfmrh(2, 11); R.translation(-0.55, -0.55, -0.55); brep.applyTransformation(R); brep.validateModel(); //brep = createCircle(0.5, 0.5, 0.5, 0.1, 12); // brep.validateModel(); parent.theScene.addThing(brep); } else if ( label.equals("IDC_CREATE_PARAMETRICCUBICCURVE") ) { ParametricCurve curve; // Case 1: curve hard-coded in source Vector3D pointParameters[]; curve = new ParametricCurve(); // Note that an HERMITE curve uses tangent vectors, BEZIER curves // uses control points (tangent vectors are control point minus // knot position) pointParameters = new Vector3D[3]; pointParameters[0] = new Vector3D(0, 0, 0); // Position 0 pointParameters[1] = new Vector3D(0, 0, 0); // Not used pointParameters[2] = new Vector3D(0, 1, 0); // Salient tangent end curve.addPoint(pointParameters, curve.BEZIER); pointParameters = new Vector3D[3]; pointParameters[0] = new Vector3D(1, 1, 0); // Position 1 pointParameters[1] = new Vector3D(0, 1, 0); // Entry tangent end pointParameters[2] = new Vector3D(2, 1, 0); // Salient tangent end curve.addPoint(pointParameters, curve.BEZIER); pointParameters = new Vector3D[3]; pointParameters[0] = new Vector3D(2, 0, 1); // Position 2 pointParameters[1] = new Vector3D(2, 0, 0); // Entry tangent end pointParameters[2] = new Vector3D(0, 0, 0); // Not used curve.addPoint(pointParameters, curve.BEZIER); parent.theScene.addThing(curve);/* try { XmlManager.exportXml(curve, "curveTest.xml", "../../../etc/xml/vsdk.dtd"); } catch (XmlException ex1) { System.out.println("EXPORT:XmlException:" +ex1); }*//* // Case 2: curve read from a previous existing data file try { curve = (ParametricCurve)XmlManager.importXml( "curveTest.xml"); parent.theScene.addThing(curve); } catch (XmlException ex1) { System.out.println("IMPORT:XmlException:" + ex1); }*/ } else if ( label.equals("IDC_CREATE_FUNCTIONALEXPLICITSURFACE") ) { SimpleBody newThing; FunctionalExplicitSurface functionalSurface; functionalSurface = new FunctionalExplicitSurface("cos((PI*x)/2)"); functionalSurface.setBounds(-10, -10, -10, 10, 10, 10); functionalSurface.setTesselationHint(100, 100); newThing = parent.theScene.addThing(functionalSurface); newThing.getMaterial().setDoubleSided(true); } else if ( label.equals("IDC_CREATE_PARAMETRICBICUBICPATCH") ) { //- Create a Ferguson patch --------------------------------------- ParametricCurve contourHermiteLine; Vector3D pointParameters[]; contourHermiteLine = new ParametricCurve(); // Note that an HERMITE curve uses tangent vectors, BEZIER curves // uses control points (tangent vectors are control point minus // knot position) pointParameters = new Vector3D[3]; pointParameters[0] = new Vector3D(0, 0, 0); // Position 0 pointParameters[1] = new Vector3D(0, -1, 0); // Entry tangent pointParameters[2] = new Vector3D(1, 0, 0); // Salient tangent contourHermiteLine.addPoint(pointParameters, contourHermiteLine.HERMITE); pointParameters = new Vector3D[3]; pointParameters[0] = new Vector3D(1, 0, 0); // Position 1 pointParameters[1] = new Vector3D(1, 0, 0); // Entry tangent pointParameters[2] = new Vector3D(0, 1, 0); // Salient tangent contourHermiteLine.addPoint(pointParameters, contourHermiteLine.HERMITE); pointParameters = new Vector3D[3]; pointParameters[0] = new Vector3D(1, 1, 0.4); // Position 2 pointParameters[1] = new Vector3D(0, 1, 0); // Entry tangent pointParameters[2] = new Vector3D(-1, 0, 0); // Salient tangent contourHermiteLine.addPoint(pointParameters, contourHermiteLine.HERMITE); pointParameters = new Vector3D[3]; pointParameters[0] = new Vector3D(0, 1, 0); // Position 3 pointParameters[1] = new Vector3D(-1, 0, 0); // Entry tangent pointParameters[2] = new Vector3D(0, -1, 0); // Salient tangent contourHermiteLine.addPoint(pointParameters, contourHermiteLine.HERMITE); contourHermiteLine.addPoint(contourHermiteLine.getPoint(0), contourHermiteLine.HERMITE); ParametricBiCubicPatch patch; patch = new ParametricBiCubicPatch(); patch.buildFergusonPatch(contourHermiteLine); patch.setApproximationSteps(20); //parent.theScene.addThing(contourHermiteLine); SimpleBody newThing; newThing = parent.theScene.addThing(patch); newThing.getMaterial().setDoubleSided(true); //-----------------------------------------------------------------/* //- Create a Bezier patch ----------------------------------------- // Create control points 4x4 matrix Vector3D cp[][] = new Vector3D[4][4]; for ( int j = 0; j < 4; j++ ) { for ( int i = 0; i < 4; i++ ) { cp[i][j] = new Vector3D(); cp[i][j].x = ((double)i)/3-0.5; cp[i][j].y = ((double)j)/3-0.5; if ( i > 0 && i < 3 && j > 0 && j < 3 ) { cp[i][j].z = 1; } else { cp[i][j].z = 0; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -