Hi again,

I've implemented some more missing stuff. Hope it'll be useful.

/Marcus

void CylinderVolume::transform(const Matrix&  mtx)
{
    // get pos & axis
    Pnt3f p;
    Vec3f v, v2, v3;
    getAxis(p,v);

    // find perpendicular vector (to detect radius transformation)
    v2 = v;
    v2.normalize();
    v3 = v2.x() > 0.9 ? Vec3f(0,1,0) : Vec3f(1,0,0);
    v3.crossThis(v2);

    // transform
    mtx.mult(p);
    mtx.mult(v);
    mtx.mult(v3);

    // update
    setAxis(p,v);
    setRadius(getRadius() * v3.length());
}

// could be adapted for extendBy, I only use it to create a cylvolume
// from scratch.
void CylinderVolume::createFrom(Vec3f dir, Points ps)
{
    // calculate midpoint
    BoxVolume bv;
    for (unsigned int i=0; i<ps->size(); ++i) {
        bv.extendBy(ps->getValue(i));
    }
    Pnt3f cappos;
    Vec3f size;
    bv.getCenter(cappos);
    bv.getSize(size);
    for(int i=0; i<3; i++) {
        cappos[i] -= size[i] * fabs(unitaxis[i]) / 2;
    }

    Vec3f unitaxis(dir);
    unitaxis.normalize();

    float radius = getRadius();
    float lengthMax = std::numeric_limits<float>::min();
    float lengthMin = std::numeric_limits<float>::max();

    for (unsigned int i=0; i<ps->size(); ++i) {
        Pnt3f pos = ps->getValue(i);
        float projLen = unitaxis.dot(pos - cappos);
        Pnt3f closest = cappos + unitaxis * projLen;
        radius = std::max(radius, pos.dist(closest));
        lengthMax = std::max(lengthMax, projLen);
        lengthMin = std::min(lengthMin, projLen);
    }

    float length = lengthMax - lengthMin;
    cappos += unitaxis * lengthMin;
    vol.setValue(cappos, unitaxis * length, radius);

    bool valid = true;
    if (ps->size() > 1 && (length==0 || radius == 0)) {
        // log.err("Calculation yielded empty volume.");
        assert(false);
        setEmpty(true);
        valid = false;
    } else {
        valid = _finite(length) && _finite(radius);
        setInfinite(!valid);
    }
    setValid(valid);
}
}


-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO
September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices
Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA
Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
_______________________________________________
Opensg-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/opensg-users

Reply via email to