コード例 #1
0
ファイル: dc_3d.cpp プロジェクト: joaocomba/depth-complexity
void DepthComplexity3D::writeRaysSpherical(std::ostream& out, int k) {
  assert(_computeGoodRays);
  long long unsigned int total = 0;
  for(int i = 0 ; i <= k ; ++i) {
    const std::vector<Segment> & _rays = goodRays(maximum()-i);
    total += _rays.size();
  }
  out << total << "\n";

/* Simple spherical coordinates
  for(int i = 0 ; i <= k ; ++i) {
    const std::vector<Segment> & _rays = goodRays(maximum()-i);
    std::vector<Segment>::const_iterator ite = _rays.begin();
    std::vector<Segment>::const_iterator end = _rays.end();
    for (; ite != end; ++ite) {
      double a, b, c, d;
      double x1 = ite->a.x, x2 = ite->b.x, y1 = ite->a.y, y2 = ite->b.y, z1 = ite->a.z, z2 = ite->b.z;
      a = atan2(y1, x1);
      b = atan2(z1, sqrt(x1*x1 + y1*y1));
      c = atan2(y2, x2);
      d = atan2(z2, sqrt(x2*x2 + y2*y2));
      out << a << " " << b << " " << c << " " << d << " " << maximum()-i << "\n";
    }
  }
*/

  BoundingBox aabb = _mesh->aabb;
  Sphere sph;
  sph.center = aabb.center();
  sph.radius = aabb.extents().length()/2;

// Coordinates of intersection with bounding sphere
  for(int i = 0 ; i <= k ; ++i) {
    const std::vector<Segment> & _rays = goodRays(maximum()-i);
    std::vector<Segment>::const_iterator ite = _rays.begin();
    std::vector<Segment>::const_iterator end = _rays.end();
    for (; ite != end; ++ite) {
      vec3d f, s;
      assert(segmentSphereIntersection3D(*ite,sph,f,s));
      f = cartesianToSpherical(f);
      s = cartesianToSpherical(s);
      out << f.y << " " << f.z << " " << s.y << " " << s.z << " " << maximum()-i << "\n";
    }
  }
}
コード例 #2
0
ファイル: dc_3d.cpp プロジェクト: joaocomba/depth-complexity
// Call this varying palign and salign.
void DepthComplexity3D::processMeshAlign(const PlaneAlign &palign, const PlaneAlign &salign) {
  assert(palign != salign);

  BoundingBox aabb = _mesh->aabb;
  aabb.merge(aabb.min - aabb.extents()/10.0);
  aabb.merge(aabb.max + aabb.extents()/10.0);

  vec3d c0 = vec3d(aabb.min.x, aabb.min.y, aabb.min.z);
  vec3d c1 = vec3d(aabb.max.x, aabb.min.y, aabb.min.z);
  vec3d c2 = vec3d(aabb.min.x, aabb.max.y, aabb.min.z);
  vec3d c3 = vec3d(aabb.max.x, aabb.max.y, aabb.min.z);
  vec3d c4 = vec3d(aabb.min.x, aabb.min.y, aabb.max.z);
  vec3d c5 = vec3d(aabb.max.x, aabb.min.y, aabb.max.z);
  vec3d c6 = vec3d(aabb.min.x, aabb.max.y, aabb.max.z);
  vec3d c7 = vec3d(aabb.max.x, aabb.max.y, aabb.max.z);


  // generate all planes varying on z
  const unsigned steps = _discretSteps;

  for (unsigned az = 0; az<steps; ++az) {
    // double t = 3*az / (steps - 1.0) - 1; // [-1, 2]
    double t = az / (steps - 1.0);
    for (unsigned bz = 0; bz<steps; ++bz) {
      // double u = 3*bz / (steps - 1.0) - 1; // [-1, 2]
      double u = bz / (steps - 1.0);
      Segment sa, sb;
      switch (palign) {
      case AlignZ: {
        Point a = mix(c0, c4, t); // along Z
        Point b = mix(c7, c3, u); // along Z
        sa.a = sa.b = a;
        sb.a = sb.b = b;

        if (salign == AlignX) {
          // extend along X
          sa.b.x = aabb.max.x;
          sb.a.x = aabb.min.x;
        } else {
          // extend along Y
          sa.b.y = aabb.max.y;
          sb.a.y = aabb.min.y;
        }
        break;
      }
      case AlignY: {
        Point a = mix(c0, c2, t); // along Y
        Point b = mix(c7, c5, u); // along Y
        sa.a = sa.b = a;
        sb.a = sb.b = b;

        if (salign == AlignX) {
          // extend along X
          sa.b.x = aabb.max.x;
          sb.a.x = aabb.min.x;
        } else {
          // extend along Z
          sa.b.z = aabb.max.z;
          sb.a.z = aabb.min.z;
        }
        break;
      }
      case AlignX:  {
        Point a = mix(c0, c1, t);
        Point b = mix(c7, c6, u);
        sa.a = sa.b = a;
        sb.a = sb.b = b;

        if (salign == AlignY) {
          // extend along Y
          sa.b.y = aabb.max.y;
          sb.a.y = aabb.min.y;
        } else {
          // extend along Z
          sa.b.z = aabb.max.z;
          sb.a.z = aabb.min.z;
        }
        break;
      }
      }

      Segment saa, sbb;
      saa.a = sa.a;
      saa.b = sb.b;
      sbb.a = sa.b;
      sbb.b = sb.a;
      _usedPlanes.push_back(sa);
      _usedPlanes.push_back(saa);
      _usedPlanes.push_back(sb);
      _usedPlanes.push_back(sbb);

      vec4d plane = makePlane(sa.a, sa.b, sb.a);
      std::vector<Segment> segments;
      processMeshPlane(plane, &segments);

      // make the segments extra-long
      vec3d dsa = sa.b - sa.a; sa.a -= dsa; sa.b += dsa;
      vec3d dsb = sb.b - sb.a; sb.a -= dsb; sb.b += dsb;

      _dc2d->process(sa, sb, segments);

      unsigned tempMaximum = _dc2d->maximum();
      if (tempMaximum >= _maximum) {
        if (tempMaximum > _maximum) {
          _maximumRays.clear();
          _goodRays.resize(tempMaximum+1);
          _histogram.resize(tempMaximum+1);
          _intersectionPoints.clear();
          //          _intersectionSegments.clear();
        }
        _maximum = tempMaximum;
        std::vector<Segment> tempRays = _dc2d->maximumRays();

        // Testing rays and saving intersectin points.
        for (unsigned r=0; r<tempRays.size(); ++r) {
          for (unsigned s=0; s<segments.size(); ++s) {
            double t1, t2;
            if(segmentIntersection3D(tempRays[r], segments[s], &t1, &t2)) {
              _intersectionPoints.push_back(tempRays[r].a + t1*(tempRays[r].b-tempRays[r].a));
            }
          }
        }

//        _intersectionSegments.insert(_intersectionSegments.end(), segments.begin(), segments.end());
//        _intersectionPoints.insert(_intersectionPoints.end(), points.begin(), points.end());

        _maximumRays.insert(_maximumRays.end(), tempRays.begin(), tempRays.end());
        // Shouldn't the histogram be used without regard to the current tempMaximum? (changed it)
      }
      
      std::vector<unsigned long long> tempHist = _dc2d->histogram();
      for(unsigned i=0; i< tempHist.size(); ++i)
        _histogram[i] += tempHist[i];
      
      if(_computeGoodRays) {
        //std::cout << "size of goodRays: " << _goodRays.size() << " and _threshold = " << _threshold << std::endl;
        for(unsigned i = _threshold ; i <= tempMaximum ; ++i) {
          //std::cout << "i = " << i << " and size(i) = " << _dc2d->goodRays(i).size() << std::endl;
          std::vector<Segment> tempRays = _dc2d->goodRays(i);
          _goodRays[i].insert(_goodRays[i].begin(), tempRays.begin(), tempRays.end());
        }
      }
    }
  }
}