Ejemplo n.º 1
0
int CNNFilter::Compress(int nInput)
{
    // convert the input to a short and store it
    m_rbInput[0] = GetSaturatedShortFromInt(nInput);

    // figure a dot product
    int nDotProduct;
    if (m_bMMXAvailable)
        nDotProduct = CalculateDotProduct(&m_rbInput[-m_nOrder], &m_paryM[0], m_nOrder);
    else
        nDotProduct = CalculateDotProductNoMMX(&m_rbInput[-m_nOrder], &m_paryM[0], m_nOrder);

    // calculate the output
    int nOutput = nInput - ((nDotProduct + (1 << (m_nShift - 1))) >> m_nShift);

    // adapt
    if (m_bMMXAvailable)
        Adapt(&m_paryM[0], &m_rbDeltaM[-m_nOrder], -nOutput, m_nOrder);
    else
        AdaptNoMMX(&m_paryM[0], &m_rbDeltaM[-m_nOrder], nOutput, m_nOrder);

    int nTempABS = abs(nInput);

    if (nTempABS > (m_nRunningAverage * 3))
        m_rbDeltaM[0] = ((nInput >> 25) & 64) - 32;
    else if (nTempABS > (m_nRunningAverage * 4) / 3)
Ejemplo n.º 2
0
void
BSPTree::BuildTree(UniquePtr<BSPTreeNode>& aRoot,
                   std::deque<gfx::Polygon3D>& aPolygons)
{
  if (aPolygons.empty()) {
    return;
  }

  const gfx::Polygon3D& splittingPlane = aRoot->First();
  std::deque<gfx::Polygon3D> backPolygons, frontPolygons;

  for (gfx::Polygon3D& polygon : aPolygons) {
    size_t pos = 0, neg = 0;
    nsTArray<float> dots = CalculateDotProduct(splittingPlane, polygon,
                                               pos, neg);

    // Back polygon
    if (pos == 0 && neg > 0) {
      backPolygons.push_back(std::move(polygon));
    }
    // Front polygon
    else if (pos > 0 && neg == 0) {
     frontPolygons.push_back(std::move(polygon));
    }
    // Coplanar polygon
    else if (pos == 0 && neg == 0) {
      aRoot->polygons.push_back(std::move(polygon));
    }
    // Polygon intersects with the splitting plane.
    else if (pos > 0 && neg > 0) {
      nsTArray<gfx::Point3D> backPoints, frontPoints;
      SplitPolygon(splittingPlane, polygon, dots, backPoints, frontPoints);

      backPolygons.push_back(gfx::Polygon3D(std::move(backPoints)));
      frontPolygons.push_back(gfx::Polygon3D(std::move(frontPoints)));
    }
  }

  if (!backPolygons.empty()) {
    aRoot->back.reset(new BSPTreeNode(PopFront(backPolygons)));
    BuildTree(aRoot->back, backPolygons);
  }

  if (!frontPolygons.empty()) {
    aRoot->front.reset(new BSPTreeNode(PopFront(frontPolygons)));
    BuildTree(aRoot->front, frontPolygons);
  }
}