示例#1
0
 bool compareArraysNeg(
     const Array1 &a1, const std::string &a1_name,
     const Array2 &a2, const std::string &a2_name,
     FancyOStream &out
     )
 {
   bool success = true;
   out << "Comparing " << a1_name << " == -(" << a2_name << ") ... ";
   const int n = a1.size();
   // Compare sizes
   if (as<int>(a2.size()) != n) {
     out << "\nError, "<<a1_name<<".size() = "<<a1.size()<<" == " 
       << a2_name<<".size() = "<<a2.size()<<" : failed!\n";
     return false;
   }
   // Compare elements
   for( int i = 0; i < n; ++i ) {
     const bool result = ( a1[i] == -a2[i] ); // Tests C::operator[](i) const
     if (!result) {
       out << "\nError, "<<a1_name<<"["<<i<<"] = "<<a1[i]<<" == -("
         << a2_name<<"["<<i<<"]) = -("<<a2[i]<<"): failed!\n";
       success = false;
     }
   }
   if (success) {
     out << "passed\n";
   }
   return success;
 }
void SphSystemData2::computeMass() {
    Array1<Vector2D> points;
    TrianglePointGenerator pointsGenerator;
    BoundingBox2D sampleBound(
        Vector2D(-1.5*_kernelRadius, -1.5*_kernelRadius),
        Vector2D(1.5*_kernelRadius, 1.5*_kernelRadius));

    pointsGenerator.generate(sampleBound, _targetSpacing, &points);

    double maxNumberDensity = 0.0;
    SphStdKernel2 kernel(_kernelRadius);

    for (size_t i = 0; i < points.size(); ++i) {
        const Vector2D& point = points[i];
        double sum = 0.0;

        for (size_t j = 0; j < points.size(); ++j) {
            const Vector2D& neighborPoint = points[j];
            sum += kernel(neighborPoint.distanceTo(point));
        }

        maxNumberDensity = std::max(maxNumberDensity, sum);
    }

    JET_ASSERT(maxNumberDensity > 0);

    double newMass = _targetDensity / maxNumberDensity;

    ParticleSystemData2::setMass(newMass);
}
示例#3
0
void particlesToObj(const Array1<Vector3D>& positions, const Size3& resolution,
                    const Vector3D& gridSpacing, const Vector3D& origin,
                    double kernelRadius, const std::string& method,
                    const std::string& objFilename) {
    PointsToImplicit3Ptr converter;
    if (method == kSpherical) {
        converter =
            std::make_shared<SphericalPointsToImplicit3>(kernelRadius, false);
    } else if (method == kSph) {
        converter = std::make_shared<SphPointsToImplicit3>(
            kernelRadius, sSphCutOffDensity, false);
    } else if (method == kZhuBridson) {
        converter = std::make_shared<ZhuBridsonPointsToImplicit3>(
            kernelRadius, sZhuBridsonCutOffThreshold, false);
    } else {
        converter = std::make_shared<AnisotropicPointsToImplicit3>(
            kernelRadius, sAnisoCutOffDensity, sAnisoPositionSmoothingFactor,
            sAnisoMinNumNeighbors, false);
    }

    VertexCenteredScalarGrid3 sdf(resolution, gridSpacing, origin);
    printInfo(resolution, sdf.boundingBox(), gridSpacing, positions.size(),
              method);

    converter->convert(positions, &sdf);

    triangulateAndSave(sdf, objFilename);
}
示例#4
0
void particlesToXml(const Array1<Vector3D>& positions,
                    const std::string& xmlFilename) {
    printInfo(positions.size());

    std::ofstream file(xmlFilename.c_str());
    if (file) {
        printf("Writing %s...\n", xmlFilename.c_str());

        file << "<scene version=\"0.5.0\">";

        for (const auto& pos : positions) {
            file << "<shape type=\"instance\">";
            file << "<ref id=\"spheres\"/>";
            file << "<transform name=\"toWorld\">";

            char buffer[64];
            snprintf(buffer, sizeof(buffer),
                     "<translate x=\"%f\" y=\"%f\" z=\"%f\"/>", pos.x, pos.y,
                     pos.z);
            file << buffer;

            file << "</transform>";
            file << "</shape>";
        }

        file << "</scene>";

        file.close();
    } else {
        printf("Cannot write file %s.\n", xmlFilename.c_str());
        exit(EXIT_FAILURE);
    }
}
bool Teuchos::compareFloatingArrays(
  const Array1 &a1, const std::string &a1_name,
  const Array2 &a2, const std::string &a2_name,
  const ScalarMag &tol,
  Teuchos::FancyOStream &out
  )
{
  using Teuchos::as;
  bool success = true;

  out << "Comparing " << a1_name << " == " << a2_name << " ... ";

  const int n = a1.size();

  // Compare sizes
  if (as<int>(a2.size()) != n) {
    out << "\nError, "<<a1_name<<".size() = "<<a1.size()<<" == " 
        << a2_name<<".size() = "<<a2.size()<<" : failed!\n";
    return false;
  }
  
  // Compare elements
  for( int i = 0; i < n; ++i ) {
    const ScalarMag err = relErr( a1[i], a2[i] );
    if ( err > tol ) {
      out
        <<"\nError, relErr("<<a1_name<<"["<<i<<"],"
        <<a2_name<<"["<<i<<"]) = relErr("<<a1[i]<<","<<a2[i]<<") = "
        <<err<<" <= tol = "<<tol<<": failed!\n";
      success = false;
    }
  }
  if (success) {
    out << "passed\n";
  }

  return success;

}