use of facetmodeller.sections.SectionVector in project facetmodeller by pglelievre.
the class DeleteSectionMenuTask method execute.
@Override
public void execute() {
// Check for the required information:
if (!check()) {
return;
}
// Ask user for confirmation:
int response = Dialogs.confirm(controller, "Are you sure you want to remove the current section?", title());
// user cancelled
if (response != Dialogs.OK_OPTION) {
return;
}
// Store the selections in the group selector objects for use later:
int ind = controller.getSelectedCurrentSectionIndex();
SectionVector selectedOtherSections = controller.getSelectedOtherSections();
// Change those selections to remove the current section:
Section currentSection = controller.getSelectedCurrentSection();
if (selectedOtherSections != null) {
selectedOtherSections.remove(currentSection);
}
// Remove the section:
RemoveSectionCommand com = new RemoveSectionCommand(controller, currentSection);
com.execute();
controller.undoVectorAdd(com);
// Reset the selections:
if (ind == 0) {
controller.clearCurrentSectionSelection();
} else {
// positions the current section to that before the one deleted
controller.setSelectedCurrentSectionIndex(ind - 1);
}
if (selectedOtherSections != null) {
controller.setSelectedOtherSections(selectedOtherSections);
}
// Tell the controller that the section selection has changed:
controller.sectionSelectionChanged(true);
}
use of facetmodeller.sections.SectionVector in project facetmodeller by pglelievre.
the class CopySectionMenuTask method execute.
@Override
public void execute() {
// Check for the required information:
if (!check()) {
return;
}
// Store the selections in the group selector objects for use later:
int ind = controller.getSelectedCurrentSectionIndex();
SectionVector selectedOtherSections = controller.getSelectedOtherSections();
// Deep copy the basic section information:
Section currentSection = controller.getSelectedCurrentSection();
Section newSection = currentSection.copySection();
// this should only happen for a SnapshotSection (redundant check)
if (newSection == null) {
return;
}
// Deep copy the on-section nodes but don't link to any facets or sections:
NodeVector newNodes = currentSection.getNodes().deepCopyNodesOnPointAndGroup();
// Link the nodes to the new section:
newNodes.setSection(newSection);
// Add the nodes to the plc using the AddNodeCommand:
ModelManager modelManager = controller.getModelManager();
for (int i = 0; i < newNodes.size(); i++) {
AddNodeCommand addNodeCommand = new AddNodeCommand(modelManager, newNodes.get(i), title());
addNodeCommand.execute();
}
// Add the new section to the section vector:
controller.addSection(newSection);
// Update the clickable lists:
controller.updateSectionSelectors();
// Reset the selections:
// positions the current section to the new section
controller.setSelectedCurrentSectionIndex(ind + 1);
if (selectedOtherSections != null) {
selectedOtherSections.add(newSection);
controller.setSelectedOtherSections(selectedOtherSections);
}
// Tell the controller that the section selection has changed:
controller.sectionSelectionChanged(true);
}
use of facetmodeller.sections.SectionVector in project facetmodeller by pglelievre.
the class SectionSelector method getSelectedSections.
/**
* Getter for the selected Section objects or null if no sections exist.
* @return
*/
public SectionVector getSelectedSections() {
// Check for no sections loaded:
if (vector.isEmpty()) {
return null;
}
SectionVector sections = new SectionVector();
int[] ind = getSelectedIndices();
if (ind == null) {
return null;
}
for (int i = 0; i < ind.length; i++) {
Section s = vector.get(ind[i]);
sections.add(s);
}
return sections;
}
use of facetmodeller.sections.SectionVector in project facetmodeller by pglelievre.
the class SessionLoader method loadSessionAscii1.
private static boolean loadSessionAscii1(FacetModeller controller, File file, boolean merge) {
int loadVersion = 1;
// We will be constructing some new objects as we read the file:
PLC plc = new PLC();
SectionVector sections = new SectionVector();
GroupVector groups = new GroupVector();
// We will be saving some information to set later:
int ndim;
Dir3D sliceDirection = Dir3D.X;
// these colours will be overwritten
Color calibrationColor = Color.CYAN;
Color edgeColor = Color.BLACK;
Color defineFacetEdgeColor = Color.WHITE;
int pointWidth = 5;
int lineWidth = 1;
// Open the file for reading:
BufferedReader reader = FileUtils.openForReading(file);
if (reader == null) {
return false;
}
// Put everything below in an infinite loop that we can break out of when something goes wrong:
boolean ok = true;
while (true) {
// Read the floored version number:
String textLine = FileUtils.readLine(reader);
if (textLine == null) {
ok = false;
break;
}
textLine = textLine.trim();
String[] ss = textLine.split("[ ]+", 2);
int version;
try {
// converts to integer
version = Integer.parseInt(ss[0].trim());
} catch (NumberFormatException e) {
ok = false;
break;
}
if (!ok) {
break;
}
// Check the version number:
if (version != loadVersion) {
// Close the file:
FileUtils.close(reader);
// Return unsuccessfully:
return false;
}
// Read the number of dimensions, nodes, facets, regions, samples and groups:
textLine = FileUtils.readLine(reader);
if (textLine == null) {
ok = false;
break;
}
int nnodes, nregions, nfacets, nsections, ngroups;
textLine = textLine.trim();
ss = textLine.split("[ ]+", 7);
try {
// converts to integer
ndim = Integer.parseInt(ss[0].trim());
// converts to integer
nnodes = Integer.parseInt(ss[1].trim());
// converts to integer
nfacets = Integer.parseInt(ss[2].trim());
// converts to integer
nregions = Integer.parseInt(ss[3].trim());
// converts to integer
nsections = Integer.parseInt(ss[4].trim());
// converts to integer
ngroups = Integer.parseInt(ss[5].trim());
} catch (NumberFormatException | ArrayIndexOutOfBoundsException e) {
ok = false;
break;
}
if (!ok) {
break;
}
// Check ndim:
if (ndim != controller.numberOfDimensions()) {
ok = false;
break;
}
// Loop over each node:
for (int i = 0; i < nnodes; i++) {
// Read the coordinates of the ith node:
textLine = FileUtils.readLine(reader);
if (textLine == null) {
ok = false;
break;
}
double x, y;
textLine = textLine.trim();
ss = textLine.split("[ ]+", 3);
try {
// converts to Double
x = Double.parseDouble(ss[0].trim());
// converts to Double
y = Double.parseDouble(ss[1].trim());
} catch (NumberFormatException | ArrayIndexOutOfBoundsException e) {
ok = false;
break;
}
if (!ok) {
break;
}
// Add a new node to the plc:
// section and group membership will be added later
plc.addNode(new NodeOnSection(x, y));
}
if (!ok) {
break;
}
// Loop over each facet:
for (int i = 0; i < nfacets; i++) {
// Add a new empty facet to the plc (these facets are filled later):
plc.addFacet(new Facet());
}
// Loop over each region:
for (int i = 0; i < nregions; i++) {
// Read the coordinates of the ith region:
textLine = FileUtils.readLine(reader);
if (textLine == null) {
ok = false;
break;
}
double x, y;
textLine = textLine.trim();
ss = textLine.split("[ ]+", 3);
try {
// converts to Double
x = Double.parseDouble(ss[0].trim());
// converts to Double
y = Double.parseDouble(ss[1].trim());
} catch (NumberFormatException | ArrayIndexOutOfBoundsException e) {
ok = false;
break;
}
if (!ok) {
break;
}
// Add a new region to the plc:
// section and group membership will be added later
plc.addRegion(new Region(false, x, y));
}
if (!ok) {
break;
}
// Loop over each section:
for (int i = 0; i < nsections; i++) {
// Read the file name:
textLine = FileUtils.readLine(reader);
File f;
if (textLine == null) {
ok = false;
break;
}
try {
URI uri = new URI(textLine);
f = new File(uri);
} catch (URISyntaxException e) {
ok = false;
break;
}
if (!ok) {
break;
}
// Create a new Section object linked to that file:
Section section = new ImageCrossSection(f);
// Read the location coordinate:
textLine = FileUtils.readLine(reader);
if (textLine == null) {
ok = false;
break;
}
textLine = textLine.trim();
ss = textLine.split("[ ]+", 2);
double loc;
try {
// converts to Double
loc = Double.parseDouble(ss[0].trim());
} catch (NumberFormatException e) {
ok = false;
break;
}
if (!ok) {
break;
}
// Read the typed and clicked points:
double x, y;
textLine = FileUtils.readLine(reader);
if (textLine == null) {
ok = false;
break;
}
textLine = textLine.trim();
if (!textLine.startsWith("null")) {
ss = textLine.split("[ ]+", 3);
try {
// converts to Double
x = Double.parseDouble(ss[0].trim());
// converts to Double
y = Double.parseDouble(ss[1].trim());
} catch (NumberFormatException | ArrayIndexOutOfBoundsException e) {
ok = false;
break;
}
if (!ok) {
break;
}
section.setTyped1(new MyPoint3D(x, y, sliceDirection, loc));
}
textLine = FileUtils.readLine(reader);
if (textLine == null) {
ok = false;
break;
}
textLine = textLine.trim();
if (!textLine.startsWith("null")) {
ss = textLine.split("[ ]+", 3);
try {
// converts to Double
x = Double.parseDouble(ss[0].trim());
// converts to Double
y = Double.parseDouble(ss[1].trim());
} catch (NumberFormatException | ArrayIndexOutOfBoundsException e) {
ok = false;
break;
}
if (!ok) {
break;
}
section.setTyped2(new MyPoint3D(x, y, sliceDirection, loc));
}
textLine = FileUtils.readLine(reader);
if (textLine == null) {
ok = false;
break;
}
textLine = textLine.trim();
if (!textLine.startsWith("null")) {
ss = textLine.split("[ ]+", 3);
try {
// converts to Double
x = Double.parseDouble(ss[0].trim());
// converts to Double
y = Double.parseDouble(ss[1].trim());
} catch (NumberFormatException | ArrayIndexOutOfBoundsException e) {
ok = false;
break;
}
if (!ok) {
break;
}
section.setClicked1(new MyPoint2D(x, y));
}
textLine = FileUtils.readLine(reader);
if (textLine == null) {
ok = false;
break;
}
textLine = textLine.trim();
if (!textLine.startsWith("null")) {
ss = textLine.split("[ ]+", 3);
try {
// converts to Double
x = Double.parseDouble(ss[0].trim());
// converts to Double
y = Double.parseDouble(ss[1].trim());
} catch (NumberFormatException | ArrayIndexOutOfBoundsException e) {
ok = false;
break;
}
if (!ok) {
break;
}
section.setClicked2(new MyPoint2D(x, y));
}
// Add the section to the list of sections:
sections.add(section);
}
if (!ok) {
break;
}
// Loop over each group:
for (int i = 0; i < ngroups; i++) {
// Create the group object:
Group group = new Group();
// Read the group name:
textLine = FileUtils.readLine(reader);
if (textLine == null) {
ok = false;
break;
}
group.setName(textLine.trim());
// Read the group colours:
Color col;
textLine = FileUtils.readLine(reader);
if (textLine == null) {
ok = false;
break;
}
try {
// parse from RGB string
col = new Color(Integer.parseInt(textLine.trim()));
} catch (NumberFormatException e) {
ok = false;
break;
}
group.setNodeColor(col);
textLine = FileUtils.readLine(reader);
if (textLine == null) {
ok = false;
break;
}
try {
// parse from RGB string
col = new Color(Integer.parseInt(textLine.trim()));
} catch (NumberFormatException e) {
ok = false;
break;
}
group.setFacetColor(col);
textLine = FileUtils.readLine(reader);
if (textLine == null) {
ok = false;
break;
}
try {
// parse from RGB string
col = new Color(Integer.parseInt(textLine.trim()));
} catch (NumberFormatException e) {
ok = false;
break;
}
group.setRegionColor(col);
// Add the group to the list of groups:
groups.add(group);
}
if (!ok) {
break;
}
// Loop over each node:
for (int i = 0; i < nnodes; i++) {
Node node = plc.getNode(i);
// The node gets linked to the facets in the loop over each facet below.
// Read the section id:
textLine = FileUtils.readLine(reader);
if (textLine == null) {
ok = false;
break;
}
textLine = textLine.trim();
ss = textLine.split("[ ]+", 2);
// section id
int id;
try {
// converts to integer
id = Integer.parseInt(ss[0].trim());
} catch (NumberFormatException e) {
ok = false;
break;
}
// Cross-link the node and section:
node.setSection(sections.get(id));
sections.get(id).addNode(node);
// Read the group id:
textLine = FileUtils.readLine(reader);
if (textLine == null) {
ok = false;
break;
}
textLine = textLine.trim();
ss = textLine.split("[ ]+", 2);
try {
// converts to integer
id = Integer.parseInt(ss[0].trim());
} catch (NumberFormatException e) {
ok = false;
break;
}
// Cross-link the node and group:
node.setGroup(groups.get(id));
groups.get(id).addNode(node);
}
if (!ok) {
break;
}
// Loop over each facet:
for (int i = 0; i < nfacets; i++) {
Facet facet = plc.getFacet(i);
// Read the node id's and link those nodes to the facet:
textLine = FileUtils.readLine(reader);
if (textLine == null) {
ok = false;
break;
}
textLine = textLine.trim();
ss = textLine.split("[ ]+");
// number of nodes
int n;
try {
// converts to integer
n = Integer.parseInt(ss[0].trim());
} catch (NumberFormatException e) {
ok = false;
break;
}
if (!ok) {
break;
}
for (int j = 0; j < n; j++) {
// node id
int id;
try {
// converts to integer
id = Integer.parseInt(ss[j + 1].trim());
} catch (NumberFormatException | ArrayIndexOutOfBoundsException e) {
ok = false;
break;
}
// Cross-link the facet and node:
facet.addNode(plc.getNode(id));
plc.getNode(id).addFacet(facet);
}
// Read the section id's:
textLine = FileUtils.readLine(reader);
if (textLine == null) {
ok = false;
break;
}
/*
textLine = textLine.trim();
ss = textLine.split("[ ]+");
try {
n = Integer.parseInt(ss[0].trim()); // converts to integer
} catch (NumberFormatException e) { ok=false; break; }
if (!ok) { break; }
for (int j=0 ; j<n ; j++ ) {
int id;
try {
id = Integer.parseInt(ss[j+1].trim()); // converts to integer
} catch (NumberFormatException | ArrayIndexOutOfBoundsException e) { ok=false; break; }
// Cross-link the facet and section:
// facet.addSection( sections.get(id) ); // no longer necessary because facet sections defined by the facet nodes
sections.get(id).addFacet(facet);
}
*/
// Read the group id:
textLine = FileUtils.readLine(reader);
if (textLine == null) {
ok = false;
break;
}
textLine = textLine.trim();
ss = textLine.split("[ ]+", 2);
int id;
try {
// converts to integer
id = Integer.parseInt(ss[0].trim());
} catch (NumberFormatException e) {
ok = false;
break;
}
// Cross-link the facet and group:
facet.setGroup(groups.get(id));
groups.get(id).addFacet(facet);
}
if (!ok) {
break;
}
// Loop over each region:
for (int i = 0; i < nregions; i++) {
Region region = plc.getRegion(i);
// Read the section id:
textLine = FileUtils.readLine(reader);
if (textLine == null) {
ok = false;
break;
}
textLine = textLine.trim();
ss = textLine.split("[ ]+", 2);
int id;
try {
// converts to integer
id = Integer.parseInt(ss[0].trim());
} catch (NumberFormatException e) {
ok = false;
break;
}
// Cross-link the region and section:
region.setSection(sections.get(id));
sections.get(id).addRegion(region);
// Read the group id and link that group to the node:
textLine = FileUtils.readLine(reader);
if (textLine == null) {
ok = false;
break;
}
textLine = textLine.trim();
ss = textLine.split("[ ]+", 2);
try {
// converts to integer
id = Integer.parseInt(ss[0].trim());
} catch (NumberFormatException e) {
ok = false;
break;
}
// Cross-link the region and group:
region.setGroup(groups.get(id));
// groups.get(id).setRegion(region);
groups.get(id).addRegion(region);
}
if (!ok) {
break;
}
// ---------- Finish with the rest of the information: ----------
// Read slice direction:
textLine = FileUtils.readLine(reader);
if (textLine == null) {
ok = false;
break;
}
// textLine = textLine.trim();
// ss = textLine.split("[ ]+",2);
// try {
// int idir = Integer.parseInt(ss[0].trim()); // converts to integer
// sliceDirection = Dir3D.fromInt(idir);
// } catch (NumberFormatException e) { ok=false; break; }
// Read painting colours, etc.:
textLine = FileUtils.readLine(reader);
if (textLine == null) {
ok = false;
break;
}
try {
// parse from RGB string
calibrationColor = new Color(Integer.parseInt(textLine.trim()));
} catch (NumberFormatException e) {
ok = false;
break;
}
textLine = FileUtils.readLine(reader);
if (textLine == null) {
ok = false;
break;
}
try {
// parse from RGB string
edgeColor = new Color(Integer.parseInt(textLine.trim()));
} catch (NumberFormatException e) {
ok = false;
break;
}
textLine = FileUtils.readLine(reader);
if (textLine == null) {
ok = false;
break;
}
try {
// parse from RGB string
defineFacetEdgeColor = new Color(Integer.parseInt(textLine.trim()));
} catch (NumberFormatException e) {
ok = false;
break;
}
textLine = FileUtils.readLine(reader);
if (textLine == null) {
ok = false;
break;
}
try {
pointWidth = Integer.parseInt(textLine.trim());
} catch (NumberFormatException e) {
ok = false;
break;
}
textLine = FileUtils.readLine(reader);
if (textLine == null) {
ok = false;
break;
}
try {
lineWidth = Integer.parseInt(textLine.trim());
} catch (NumberFormatException e) {
ok = false;
break;
}
// Always break from while here:
break;
}
// Close the file:
FileUtils.close(reader);
// Check for a problem:
if (!ok) {
return false;
}
// Reset the FacetModeller plc, section lists and group lists:
controller.resetPLC(plc, merge);
controller.resetSectionVector(sections, merge);
controller.resetGroupVector(groups, merge);
// If it is a large model then don't display anything:
if (plc.numberOfNodes() >= LARGE_MODEL) {
controller.clearGroupSelections();
}
// Reset some other information:
if (!merge) {
controller.setCalibrationColor(calibrationColor);
controller.setEdgeColor(edgeColor);
controller.setDefineFacetEdgeColor(defineFacetEdgeColor);
controller.setPointWidth(pointWidth);
controller.setLineWidth(lineWidth);
}
// Return successfully:
return true;
}
use of facetmodeller.sections.SectionVector in project facetmodeller by pglelievre.
the class NodeVector method getSections.
/**
* Gets the section memberships for all nodes.
* @return
*/
public SectionVector getSections() {
SectionVector sections = new SectionVector();
for (int i = 0; i < size(); i++) {
Section s = get(i).getSection();
// duplicates are not added (checked in this call)
sections.add(s);
}
return sections;
}
Aggregations