예제 #1
0
double GeometryTools::getAngle(const cvf::Vec3d& positiveNormalAxis, const cvf::Vec3d& v1, const cvf::Vec3d& v2)
{
    bool isOk = false;
    cvf::Vec3d v1N = v1.getNormalized(&isOk);
    if (!isOk) return 0;
    cvf::Vec3d v2N = v2.getNormalized();
    if (!isOk) return 0;

    double cosAng = v1N * v2N;
    // Guard acos against out-of-domain input
    if (cosAng <= -1.0) 
    {
        cosAng = -1.0; 
    }
    else if (cosAng >= 1.0)
    {
        cosAng = 1.0; 
    }
    double angle = acos(cosAng);

    cvf::Vec3d crossProd = v1N ^ v2N;
    double sign = positiveNormalAxis * crossProd;
    if (sign < 0)
    {
        angle = 2*MY_PI - angle;
    }
    return angle;
}
예제 #2
0
//--------------------------------------------------------------------------------------------------
/// 
//--------------------------------------------------------------------------------------------------
void RigReservoirBuilderMock::appendNodes(const cvf::Vec3d& min, const cvf::Vec3d& max, const cvf::Vec3st& cubeDimension, std::vector<cvf::Vec3d>& nodes)
{
    double dx = (max.x() - min.x()) / static_cast<double>(cubeDimension.x());
    double dy = (max.y() - min.y()) / static_cast<double>(cubeDimension.y());
    double dz = (max.z() - min.z()) / static_cast<double>(cubeDimension.z());

    double zPos = min.z();

    size_t k;
    for (k = 0; k < cubeDimension.z(); k++)
    {
        double yPos = min.y();

        size_t j;
        for (j = 0; j < cubeDimension.y(); j++)
        {
            double xPos = min.x();

            size_t i;
            for (i = 0; i < cubeDimension.x(); i++)
            {
                cvf::Vec3d min(xPos, yPos, zPos);
                cvf::Vec3d max(xPos + dx, yPos + dy, zPos + dz);

                appendCubeNodes(min, max, nodes);

                xPos += dx;
            }

            yPos += dy;
        }

        zPos += dz;
    }
}
예제 #3
0
int GeometryTools::findClosestAxis(const cvf::Vec3d& vec )
{
    int closestAxis = 0;
    double maxComponent = fabs(vec.x());

    if (fabs(vec.y()) > maxComponent)
    {
        maxComponent = (float)fabs(vec.y());
        closestAxis = 1;
    }

    if (fabs(vec.z()) > maxComponent)
    {
        closestAxis = 2;
    }

    return closestAxis;
}
예제 #4
0
int largestComponent(const cvf::Vec3d v)
{
    double maxLength = v.x();
    int idx = 0;

    if (v.y() > maxLength)
    {
        maxLength = v.y();
        idx = 1;
    }

    if (v.z() > maxLength)
    {
        maxLength = v.z();
        idx = 2;
    }

    return idx;
}
예제 #5
0
double largestComponent(const cvf::Vec3d v, cvf::uint* largestIndex)
{
    double length = v.x();
    cvf::uint idx = 0;

    if (v.y() > length)
    {
        length = v.y();
        idx = 1;
    }

    if (v.z() > length)
    {
        length = v.z();
        idx = 2;
    }

    if (largestIndex) *largestIndex = idx;

    return length;
}
예제 #6
0
double GeometryTools::getAngle(const cvf::Vec3d& v1, const cvf::Vec3d& v2)
{
    bool isOk = false;
    cvf::Vec3d v1N = v1.getNormalized(&isOk);
    if (!isOk) return 0;
    cvf::Vec3d v2N = v2.getNormalized();
    if (!isOk) return 0;

    double cosAng = v1N * v2N;
    // Guard acos against out-of-domain input
    if (cosAng <= -1.0) 
    {
        cosAng = -1.0; 
    }
    else if (cosAng >= 1.0)
    {
        cosAng = 1.0; 
    }
    double angle = acos(cosAng);

    return angle;
}
예제 #7
0
//--------------------------------------------------------------------------------------------------
/// Set the axes
/// 
/// The specified axes will be normalized
//--------------------------------------------------------------------------------------------------
void RivPatchGenerator::setAxes(const cvf::Vec3d& axisU, const cvf::Vec3d& axisV)
{
    m_axisU = axisU.getNormalized();
    m_axisV = axisV.getNormalized();
}
예제 #8
0
//--------------------------------------------------------------------------------------------------
/// 
//--------------------------------------------------------------------------------------------------
void RigReservoirBuilderMock::appendCubeNodes(const cvf::Vec3d& min, const cvf::Vec3d& max, std::vector<cvf::Vec3d>& nodes)
{
    //
    //     7---------6                Faces:
    //    /|        /|     |k           0 bottom   0, 3, 2, 1
    //   / |       / |     | /j         1 top      4, 5, 6, 7
    //  4---------5  |     |/           2 front    0, 1, 5, 4
    //  |  3------|--2     *---i        3 right    1, 2, 6, 5
    //  | /       | /                   4 back     3, 7, 6, 2
    //  |/        |/                    5 left     0, 4, 7, 3
    //  0---------1                     

    cvf::Vec3d v0(min.x(), min.y(), min.z());
    cvf::Vec3d v1(max.x(), min.y(), min.z());
    cvf::Vec3d v2(max.x(), max.y(), min.z());
    cvf::Vec3d v3(min.x(), max.y(), min.z());
             
    cvf::Vec3d v4(min.x(), min.y(), max.z());
    cvf::Vec3d v5(max.x(), min.y(), max.z());
    cvf::Vec3d v6(max.x(), max.y(), max.z());
    cvf::Vec3d v7(min.x(), max.y(), max.z());

    nodes.push_back(v0);
    nodes.push_back(v1);
    nodes.push_back(v2);
    nodes.push_back(v3);
    nodes.push_back(v4);
    nodes.push_back(v5);
    nodes.push_back(v6);
    nodes.push_back(v7);
}
예제 #9
0
//--------------------------------------------------------------------------------------------------
/// 
//--------------------------------------------------------------------------------------------------
void XmlElementImpl::setAttributeVector(const String& attributeName, const cvf::Vec3d& val)
{
    String valString =  String::number(val.x()) + " " + String::number(val.y()) + " " + String::number(val.z());

    setAttributeString(attributeName, valString);
}