Example #1
0
 @Test
 public void testContents() {
   final int[] a = new int[] {1, 2, 3};
   final IntVec v = new IntVec(a);
   assertEquals(a.length, v.dim());
   for (int i = 0; i < a.length; ++i) {
     assertEquals(a[i], v.get(i));
   }
 }
Example #2
0
 @Test
 public void testAdvanceV() {
   final int[] b = new int[5];
   for (int i = 0; i < 3; ++i) {
     b[i + 1] = i + 1;
   }
   final IntVec bv = new IntVec(b);
   final SeqLE seq = new SeqLE(bv);
   final int[] x = new int[5];
   int n = 0;
   do {
     for (int i = 0; i < x.length; ++i) {
       assertTrue((x[i] >= 0) && (x[i] <= bv.get(i)));
     }
     ++n;
   } while (seq.advance(x));
   assertEquals(24, n);
 }
Example #3
0
 @Test
 public void testComp() {
   final IntVec iv0 = new IntVec(new int[] {0, 0, 0});
   final IntVec ivnz = new IntVec(new int[] {0, 1, 0});
   final Set<IntVec> s = new HashSet<IntVec>();
   for (final IntVec v : new IntVec[] {iv0, ivnz}) {
     assertTrue(v.compareTo(v) == 0);
     assertTrue(v.equals(v));
     s.add(v);
   }
   assertEquals(2, s.size());
   assertTrue(iv0.compareTo(ivnz) != 0);
   assertFalse(iv0.equals(ivnz));
   assertFalse(iv0.toString().compareTo(ivnz.toString()) == 0);
 }
Example #4
0
  ///////////////////////////////////////////////////////////////////////////////////////////
  // Build()
  //
  // Builds a strip forward as far as we can go, then builds backwards, and joins the two lists
  //
  void build(EdgeInfoVec edgeInfos, FaceInfoVec faceInfos) {
    // used in building the strips forward and backward
    IntVec scratchIndices = new IntVec();

    // build forward... start with the initial face
    FaceInfoVec forwardFaces = new FaceInfoVec();
    FaceInfoVec backwardFaces = new FaceInfoVec();
    forwardFaces.add(m_startInfo.m_startFace);

    markTriangle(m_startInfo.m_startFace);

    int v0 = (m_startInfo.m_toV1 ? m_startInfo.m_startEdge.m_v0 : m_startInfo.m_startEdge.m_v1);
    int v1 = (m_startInfo.m_toV1 ? m_startInfo.m_startEdge.m_v1 : m_startInfo.m_startEdge.m_v0);

    // easiest way to get v2 is to use this function which requires the
    // other indices to already be in the list.
    scratchIndices.add(v0);
    scratchIndices.add(v1);
    int v2 = Stripifier.getNextIndex(scratchIndices, m_startInfo.m_startFace);
    scratchIndices.add(v2);

    //
    // build the forward list
    //
    int nv0 = v1;
    int nv1 = v2;

    FaceInfo nextFace = Stripifier.findOtherFace(edgeInfos, nv0, nv1, m_startInfo.m_startFace);
    while (nextFace != null && !isMarked(nextFace)) {
      // check to see if this next face is going to cause us to die soon
      int testnv0 = nv1;
      int testnv1 = Stripifier.getNextIndex(scratchIndices, nextFace);

      FaceInfo nextNextFace = Stripifier.findOtherFace(edgeInfos, testnv0, testnv1, nextFace);

      if ((nextNextFace == null) || (isMarked(nextNextFace))) {
        // uh, oh, we're following a dead end, try swapping
        FaceInfo testNextFace = Stripifier.findOtherFace(edgeInfos, nv0, testnv1, nextFace);

        if (((testNextFace != null) && !isMarked(testNextFace))) {
          // we only swap if it buys us something

          // add a "fake" degenerate face
          FaceInfo tempFace = new FaceInfo(nv0, nv1, nv0);

          forwardFaces.add(tempFace);
          markTriangle(tempFace);

          scratchIndices.add(nv0);
          testnv0 = nv0;

          ++m_numDegenerates;
        }
      }

      // add this to the strip
      forwardFaces.add(nextFace);

      markTriangle(nextFace);

      // add the index
      // nv0 = nv1;
      // nv1 = NvStripifier::GetNextIndex(scratchIndices, nextFace);
      scratchIndices.add(testnv1);

      // and get the next face
      nv0 = testnv0;
      nv1 = testnv1;

      nextFace = Stripifier.findOtherFace(edgeInfos, nv0, nv1, nextFace);
    }

    // tempAllFaces is going to be forwardFaces + backwardFaces
    // it's used for Unique()
    FaceInfoVec tempAllFaces = new FaceInfoVec();
    for (int i = 0; i < forwardFaces.size(); i++) tempAllFaces.add(forwardFaces.at(i));

    //
    // reset the indices for building the strip backwards and do so
    //
    scratchIndices.clear();
    scratchIndices.add(v2);
    scratchIndices.add(v1);
    scratchIndices.add(v0);
    nv0 = v1;
    nv1 = v0;
    nextFace = Stripifier.findOtherFace(edgeInfos, nv0, nv1, m_startInfo.m_startFace);
    while (nextFace != null && !isMarked(nextFace)) {
      // this tests to see if a face is "unique", meaning that its vertices aren't already in the
      // list
      // so, strips which "wrap-around" are not allowed
      if (!unique(tempAllFaces, nextFace)) break;

      // check to see if this next face is going to cause us to die soon
      int testnv0 = nv1;
      int testnv1 = Stripifier.getNextIndex(scratchIndices, nextFace);

      FaceInfo nextNextFace = Stripifier.findOtherFace(edgeInfos, testnv0, testnv1, nextFace);

      if ((nextNextFace == null) || (isMarked(nextNextFace))) {
        // uh, oh, we're following a dead end, try swapping
        FaceInfo testNextFace = Stripifier.findOtherFace(edgeInfos, nv0, testnv1, nextFace);
        if (((testNextFace != null) && !isMarked(testNextFace))) {
          // we only swap if it buys us something

          // add a "fake" degenerate face
          FaceInfo tempFace = new FaceInfo(nv0, nv1, nv0);

          backwardFaces.add(tempFace);
          markTriangle(tempFace);
          scratchIndices.add(nv0);
          testnv0 = nv0;

          ++m_numDegenerates;
        }
      }

      // add this to the strip
      backwardFaces.add(nextFace);

      // this is just so Unique() will work
      tempAllFaces.add(nextFace);

      markTriangle(nextFace);

      // add the index
      // nv0 = nv1;
      // nv1 = NvStripifier::GetNextIndex(scratchIndices, nextFace);
      scratchIndices.add(testnv1);

      // and get the next face
      nv0 = testnv0;
      nv1 = testnv1;
      nextFace = Stripifier.findOtherFace(edgeInfos, nv0, nv1, nextFace);
    }

    // Combine the forward and backwards stripification lists and put into our own face vector
    combine(forwardFaces, backwardFaces);
  }