my code stock.com

Morphology of elastic backbone in infinite cluster. Composite structure in percolation threshold.

Snippet options

Download: Download snippet as backbone-morphology.java.
Copy snippet: For this you need a free my code stock.com account.
Embed code : You will find the embed code for this snippet at the end of the page, if you want to embed it into a website or a blog!

/**
 * označení a morfologie páteře nekonečného clusteru
 *
 * metoda volaná nad perkolující strukturou označuje jednotlivé části
 * nekonečného clusteru a zpracovává morfologii páteře
 *
 * @throws NoSuchMethodException
 * @throws IllegalAccessException
 * @throws IllegalArgumentException
 * @throws InvocationTargetException
 * @throws IOException
 */
public void backbone() throws NoSuchMethodException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, IOException {
	//get all one electrod elements
	ArrayList<Integer> oneSide = new ArrayList<Integer>();

    // group all burning objets
    ArrayList<Object3D> burning = new ArrayList<Object3D>();

    for (int i = 0; i < objects.size(); i++) {
        if ( (Integer) objects.get(i).getBurn().get("num") != 0) {
            objects.get(i).getBurn().put("numTop", 0);
            objects.get(i).getBurn().put("numBottom", 0);
            burning.add(objects.get(i));
        }
    }

    //----------------------------------------------------------------------------------------------------------------------------------
    // burning TOP->BOTTOM
    //----------------------------------------------------------------------------------------------------------------------------------
    // init first line
    for (int i = 0; i < burning.size(); i++) {
        if ( (burning.get(i).gainMinY() < (this.startWorkY)) && (burning.get(i).gainMaxY() > (this.startWorkY)) ) {
            burning.get(i).getBurn().put("numTop", 1);
            burning.get(i).getBurn().put("from", 4);
        }
    }

    // burn
    int parent;
    boolean goOnTop = true;

    while (goOnTop) {
        goOnTop = false;

        for (int i = 0; i < burning.size(); i++) {
            if ( (Integer) burning.get(i).getBurn().get("numTop") == 0) {
                parent = this.objects.size();

                for (int j = 0; j < burning.size(); j++) {
                    if ( ( (Integer) burning.get(j).getBurn().get("numTop") > 0) && (i != j) ) {
                        //if (burning.get(i).isOverlap(burning.get(j))) {
                        if (Object3D.isOverlap(burning.get(i), burning.get(j))) {
                            parent = Math.min(parent, (Integer) burning.get(j).getBurn().get("numTop"));
                        }
                    }
                }

                if (parent != this.objects.size()) {
                    burning.get(i).getBurn().put("numTop", parent + 1);
                    goOnTop = true;
                }
            }
        }
    }


    //----------------------------------------------------------------------------------------------------------------------------------
    // burning BOTTOM->TOP
    //----------------------------------------------------------------------------------------------------------------------------------
    // init first line
    for (int i = 0; i < burning.size(); i++) {
        if ( (burning.get(i).gainMinY() < (this.endWorkY)) && (burning.get(i).gainMaxY() > (this.endWorkY)) ) {
            burning.get(i).getBurn().put("numBottom", 1);
            burning.get(i).getBurn().put("from", 2);
        }
    }

    // burn
    boolean goOnBottom = true;

    while (goOnBottom) {
        goOnBottom = false;

        for (int i = 0; i < burning.size(); i++) {
            if ( (Integer) burning.get(i).getBurn().get("numBottom") == 0) {
                parent = this.objects.size();

                for (int j = 0; j < burning.size(); j++) {
                    if ( ( (Integer) burning.get(j).getBurn().get("numBottom") > 0) && (i != j) ) {
                        //if (burning.get(i).isOverlap(burning.get(j))) {
                        if (Object3D.isOverlap(burning.get(i), burning.get(j))) {
                            parent = Math.min(parent, (Integer) burning.get(j).getBurn().get("numBottom"));
                        }
                    }
                }

                if (parent != this.objects.size()) {
                    burning.get(i).getBurn().put("numBottom", parent + 1);
                    goOnBottom = true;
                }
            }
        }
    }

    // get one side clusters
    for (int i = 0; i < burning.size(); i++) {
        if ( ( (Integer) burning.get(i).getBurn().get("numTop") == 0) || ( (Integer) burning.get(i).getBurn().get("numBottom") == 0) ) {
            burning.get(i).getBurn().put("num", -2);
            burning.get(i).setColor(new Color(0, 255, 0)); /////////////////////
        }
    }

	ArrayList<Integer> deadEnds = new ArrayList<Integer>();
	ArrayList<Integer> criticals = new ArrayList<Integer>();

	for (int i = 0; i < burning.size(); i++) {
		// burn indicator
		boolean burn = false;

		// prepare
		for (int f = 0; f < burning.size(); f++) {
			if ((Integer) burning.get(f).getBurn().get("num") != -2) {
				burning.get(f).getBurn().put("from", 0);
			}
		}

		// get indexes
		//----------------------------------------------------------------------------------------------------------------------------------
		// burning BOTTOM->TOP
		//----------------------------------------------------------------------------------------------------------------------------------
		// init first line
		for (int x = 0; x < burning.size(); x++) {
			if ( (burning.get(x).gainMinY() < (this.startWorkY)) && (burning.get(x).gainMaxY() > (this.startWorkY)) ) {
				burning.get(x).getBurn().put("from", 4);
			}
		}

		// burn
		goOnTop = true;

		while (goOnTop) {
			goOnTop = false;

			for (int topCounter = 0; topCounter < burning.size(); topCounter++) {
				if ((Integer) burning.get(topCounter).getBurn().get("from") == 0) {
					for (int j = 0; j < burning.size(); j++) {
						if ( (Integer) burning.get(j).getBurn().get("from") != 0) {
							if ( (topCounter != j) && (i != j) && (topCounter != i) ) {
    							//if ( (topCounter != j) && (i != j) ) {
								if (Object3D.isOverlap(burning.get(topCounter), burning.get(j))) {
									burning.get(topCounter).getBurn().put("from", 4);

									goOnTop = true;

									// burn thought
									if (burning.get(topCounter).gainMaxY() > (this.endWorkY)) {
										burn = true;
									}										
								}
							}
						}
					}
				}
			}
		}

		//----------------------------------------------------------------------------------------------------------------------------------
		// burning TOP->BOTTOM
		//----------------------------------------------------------------------------------------------------------------------------------
		// init first line
		for (int y = 0; y < burning.size(); y++) {
			if ( (burning.get(y).gainMinY() < (this.endWorkY)) && (burning.get(y).gainMaxY() > (this.endWorkY)) ) {
				burning.get(y).getBurn().put("from", 2);
			}
		}

		// burn
		goOnBottom = true;

		while (goOnBottom) {
			goOnBottom = false;

			for (int bottomCounter = 0; bottomCounter < burning.size(); bottomCounter++) {
				if ((Integer) burning.get(bottomCounter).getBurn().get("from") == 0) {
					for (int j = 0; j < burning.size(); j++) {
						if ( (Integer) burning.get(j).getBurn().get("from") != 0) {
							//if ( (bottomCounter != j) && (i != j) && (bottomCounter != i)) {
							if ( (bottomCounter != j) && (i != j)) {
								if (Object3D.isOverlap(burning.get(bottomCounter), burning.get(j))) {
									burning.get(bottomCounter).getBurn().put("from", 2);

									goOnBottom = true;

									// burn thought
									if (burning.get(bottomCounter).gainMinY() < (this.startWorkY)) {
										burn = true;
									}
								}
							}
						}
					}
				}
			}
		}
		// end of get indexes

		// extract dead ends
		for (int q = 0; q < burning.size(); q++) {
			if ( (Integer) burning.get(q).getBurn().get("from") == 0) {
				if (!deadEnds.contains(q)) {
					deadEnds.add(q);
				}
			}
		}

		// extract critical
		if (!burn) {
			if (!criticals.contains(i)) {
				criticals.add(i);
			}
		}
	}


	// color dead ends
	for (int i = 0; i < deadEnds.size(); i++) {
		//burning.remove(i-(comp++));
		if ( (Integer) burning.get(deadEnds.get(i)).getBurn().get("num") != 1) {
			burning.get(deadEnds.get(i)).setColor(new Color(0, 0, 255));
		}
	}

	//recolor one side elements
	for (int i = 0; i < burning.size(); i++) {
		if ( (Integer) burning.get(i).getBurn().get("num") == -2) {
			burning.get(i).setColor(new Color(0, 255, 0));
		}
	}

	// color criticals
	for (int i = 0; i < criticals.size(); i++) {
		burning.get(criticals.get(i)).setColor(new Color(255, 0, 0));
	}

}

Create a free my code stock.com account now.

my code stok.com is a free service, which allows you to save and manage code snippes of any kind and programming language. We provide many advantages for your daily work with code-snippets, also for your teamwork. Give it a try!

Find out more and register now

You can customize the height of iFrame-Codes as needed! You can find more infos in our API Reference for iframe Embeds.