Beispiel #1
0
void Grid::__init() {
	gSize = indexSize();

	if (trueDimensions() != dimensions())
		cout << gridName << ": dim = " << dimensions() << ", trueDim = "
				<< trueDimensions() << ", index range = " << String(getN())
				<< ", index size = " << indexSize() << endl;

}
Beispiel #2
0
    void ZimCreator::fillHeader(ArticleSource& src)
    {
      std::string mainAid = src.getMainPage();
      std::string layoutAid = src.getLayoutPage();

      log_debug("main aid=" << mainAid << " layout aid=" << layoutAid);

      header.setMainPage(std::numeric_limits<size_type>::max());
      header.setLayoutPage(std::numeric_limits<size_type>::max());

      if (!mainAid.empty() || !layoutAid.empty())
      {
        for (DirentsType::const_iterator di = dirents.begin(); di != dirents.end(); ++di)
        {
          if (mainAid == di->getAid())
          {
            log_debug("main idx=" << di->getIdx());
            header.setMainPage(di->getIdx());
          }

          if (layoutAid == di->getAid())
          {
            log_debug("layout idx=" << di->getIdx());
            header.setLayoutPage(di->getIdx());
          }
        }
      }

      header.setUuid( src.getUuid() );
      header.setArticleCount( dirents.size() );
      header.setUrlPtrPos( urlPtrPos() );
      header.setMimeListPos( mimeListPos() );
      header.setTitleIdxPos( titleIdxPos() );
      header.setClusterCount( clusterOffsets.size() );
      header.setClusterPtrPos( clusterPtrPos() );
      header.setChecksumPos( checksumPos() );

      log_debug(
            "mimeListSize=" << mimeListSize() <<
           " mimeListPos=" << mimeListPos() <<
           " indexPtrSize=" << urlPtrSize() <<
           " indexPtrPos=" << urlPtrPos() <<
           " indexSize=" << indexSize() <<
           " indexPos=" << indexPos() <<
           " clusterPtrSize=" << clusterPtrSize() <<
           " clusterPtrPos=" << clusterPtrPos() <<
           " clusterCount=" << clusterCount() <<
           " articleCount=" << articleCount() <<
           " articleCount=" << dirents.size() <<
           " urlPtrPos=" << header.getUrlPtrPos() <<
           " titleIdxPos=" << header.getTitleIdxPos() <<
           " clusterCount=" << header.getClusterCount() <<
           " clusterPtrPos=" << header.getClusterPtrPos() <<
           " checksumPos=" << checksumPos()
           );
    }
Beispiel #3
0
void Grid::print_indices() const {

	// check indexing:
	if (!check()) {
		print_labels();
		return;
	}

	for (unsigned int i = 0; i < indexSize(); i++) {

		// get index set:
		MultiIndexed::IndexSet is = i2x(i);

		cout << "i = " << i << " --> ";
		for (unsigned int j = 0; j < is.size(); j++) {
			cout << "x(" << j << ") = " << is[j] << "  ";
		}
		cout << "---> i = " << x2i(is);
		cout << endl;
	}

}
GLenum IndexDataManager::prepareIndexData(GLenum type, GLsizei count, Buffer *buffer, const GLvoid *indices, TranslatedIndexData *translated)
{
    if (!mStreamingBufferShort)
    {
        return GL_OUT_OF_MEMORY;
    }

    D3DFORMAT format = (type == GL_UNSIGNED_INT) ? D3DFMT_INDEX32 : D3DFMT_INDEX16;
    intptr_t offset = reinterpret_cast<intptr_t>(indices);
    bool alignedOffset = false;

    if (buffer != NULL)
    {
        switch (type)
        {
          case GL_UNSIGNED_BYTE:  alignedOffset = (offset % sizeof(GLubyte) == 0);  break;
          case GL_UNSIGNED_SHORT: alignedOffset = (offset % sizeof(GLushort) == 0); break;
          case GL_UNSIGNED_INT:   alignedOffset = (offset % sizeof(GLuint) == 0);   break;
          default: UNREACHABLE(); alignedOffset = false;
        }

        if (typeSize(type) * count + offset > static_cast<std::size_t>(buffer->size()))
        {
            return GL_INVALID_OPERATION;
        }

        indices = static_cast<const GLubyte*>(buffer->data()) + offset;
    }

    StreamingIndexBuffer *streamingBuffer = (type == GL_UNSIGNED_INT) ? mStreamingBufferInt : mStreamingBufferShort;

    StaticIndexBuffer *staticBuffer = buffer ? buffer->getStaticIndexBuffer() : NULL;
    IndexBuffer *indexBuffer = streamingBuffer;
    UINT streamOffset = 0;

    if (staticBuffer && staticBuffer->lookupType(type) && alignedOffset)
    {
        indexBuffer = staticBuffer;
        streamOffset = staticBuffer->lookupRange(offset, count, &translated->minIndex, &translated->maxIndex);

        if (streamOffset == -1)
        {
            streamOffset = (offset / typeSize(type)) * indexSize(format);
            computeRange(type, indices, count, &translated->minIndex, &translated->maxIndex);
            staticBuffer->addRange(offset, count, translated->minIndex, translated->maxIndex, streamOffset);
        }
    }
    else
    {
        int convertCount = count;

        if (staticBuffer)
        {
            if (staticBuffer->size() == 0 && alignedOffset)
            {
                indexBuffer = staticBuffer;
                convertCount = buffer->size() / typeSize(type);
            }
            else
            {
                buffer->invalidateStaticData();
                staticBuffer = NULL;
            }
        }

        void *output = NULL;
        
        if (indexBuffer)
        {
            indexBuffer->reserveSpace(convertCount * indexSize(format), type);
            output = indexBuffer->map(indexSize(format) * convertCount, &streamOffset);
        }
        
        if (output == NULL)
        {
            ERR("Failed to map index buffer.");
            return GL_OUT_OF_MEMORY;
        }

        convertIndices(type, staticBuffer ? buffer->data() : indices, convertCount, output);
        indexBuffer->unmap();

        computeRange(type, indices, count, &translated->minIndex, &translated->maxIndex);

        if (staticBuffer)
        {
            streamOffset = (offset / typeSize(type)) * indexSize(format);
            staticBuffer->addRange(offset, count, translated->minIndex, translated->maxIndex, streamOffset);
        }
    }

    translated->indexBuffer = indexBuffer->getBuffer();
    translated->serial = indexBuffer->getSerial();
    translated->startIndex = streamOffset / indexSize(format);

    if (buffer)
    {
        buffer->promoteStaticUsage(count * typeSize(type));
    }

    return GL_NO_ERROR;
}
Beispiel #5
0
NS_IMETHODIMP
nsMathMLmrootFrame::Reflow(nsPresContext*          aPresContext,
                           nsHTMLReflowMetrics&     aDesiredSize,
                           const nsHTMLReflowState& aReflowState,
                           nsReflowStatus&          aStatus)
{
  nsresult rv = NS_OK;
  nsSize availSize(aReflowState.ComputedWidth(), NS_UNCONSTRAINEDSIZE);
  nsReflowStatus childStatus;

  aDesiredSize.Width() = aDesiredSize.Height() = 0;
  aDesiredSize.SetTopAscent(0);

  nsBoundingMetrics bmSqr, bmBase, bmIndex;
  nsRenderingContext& renderingContext = *aReflowState.rendContext;

  //////////////////
  // Reflow Children

  int32_t count = 0;
  nsIFrame* baseFrame = nullptr;
  nsIFrame* indexFrame = nullptr;
  nsHTMLReflowMetrics baseSize(aReflowState.GetWritingMode());
  nsHTMLReflowMetrics indexSize(aReflowState.GetWritingMode());
  nsIFrame* childFrame = mFrames.FirstChild();
  while (childFrame) {
    // ask our children to compute their bounding metrics 
    nsHTMLReflowMetrics childDesiredSize(aReflowState.GetWritingMode(),
                                         aDesiredSize.mFlags
                                         | NS_REFLOW_CALC_BOUNDING_METRICS);
    nsHTMLReflowState childReflowState(aPresContext, aReflowState,
                                       childFrame, availSize);
    rv = ReflowChild(childFrame, aPresContext,
                     childDesiredSize, childReflowState, childStatus);
    //NS_ASSERTION(NS_FRAME_IS_COMPLETE(childStatus), "bad status");
    if (NS_FAILED(rv)) {
      // Call DidReflow() for the child frames we successfully did reflow.
      DidReflowChildren(mFrames.FirstChild(), childFrame);
      return rv;
    }
    if (0 == count) {
      // base 
      baseFrame = childFrame;
      baseSize = childDesiredSize;
      bmBase = childDesiredSize.mBoundingMetrics;
    }
    else if (1 == count) {
      // index
      indexFrame = childFrame;
      indexSize = childDesiredSize;
      bmIndex = childDesiredSize.mBoundingMetrics;
    }
    count++;
    childFrame = childFrame->GetNextSibling();
  }
  if (2 != count) {
    // report an error, encourage people to get their markups in order
    ReportChildCountError();
    rv = ReflowError(renderingContext, aDesiredSize);
    aStatus = NS_FRAME_COMPLETE;
    NS_FRAME_SET_TRUNCATION(aStatus, aReflowState, aDesiredSize);
    // Call DidReflow() for the child frames we successfully did reflow.
    DidReflowChildren(mFrames.FirstChild(), childFrame);
    return rv;
  }

  ////////////
  // Prepare the radical symbol and the overline bar

  nsRefPtr<nsFontMetrics> fm;
  nsLayoutUtils::GetFontMetricsForFrame(this, getter_AddRefs(fm));
  renderingContext.SetFont(fm);

  // For radical glyphs from TeX fonts and some of the radical glyphs from
  // Mathematica fonts, the thickness of the overline can be obtained from the
  // ascent of the glyph.  Most fonts however have radical glyphs above the
  // baseline so no assumption can be made about the meaning of the ascent.
  nscoord ruleThickness, leading, em;
  GetRuleThickness(renderingContext, fm, ruleThickness);

  char16_t one = '1';
  nsBoundingMetrics bmOne = renderingContext.GetBoundingMetrics(&one, 1);

  // get the leading to be left at the top of the resulting frame
  // this seems more reliable than using fm->GetLeading() on suspicious fonts
  GetEmHeight(fm, em);
  leading = nscoord(0.2f * em); 

  // Rule 11, App. G, TeXbook
  // psi = clearance between rule and content
  nscoord phi = 0, psi = 0;
  if (StyleFont()->mMathDisplay == NS_MATHML_DISPLAYSTYLE_BLOCK)
    phi = fm->XHeight();
  else
    phi = ruleThickness;
  psi = ruleThickness + phi/4;

  // built-in: adjust clearance psi to emulate \mathstrut using '1' (TexBook, p.131)
  if (bmOne.ascent > bmBase.ascent)
    psi += bmOne.ascent - bmBase.ascent;

  // make sure that the rule appears on on screen
  nscoord onePixel = nsPresContext::CSSPixelsToAppUnits(1);
  if (ruleThickness < onePixel) {
    ruleThickness = onePixel;
  }

  // adjust clearance psi to get an exact number of pixels -- this
  // gives a nicer & uniform look on stacked radicals (bug 130282)
  nscoord delta = psi % onePixel;
  if (delta)
    psi += onePixel - delta; // round up

  // Stretch the radical symbol to the appropriate height if it is not big enough.
  nsBoundingMetrics contSize = bmBase;
  contSize.descent = bmBase.ascent + bmBase.descent + psi;
  contSize.ascent = ruleThickness;

  // height(radical) should be >= height(base) + psi + ruleThickness
  nsBoundingMetrics radicalSize;
  mSqrChar.Stretch(aPresContext, renderingContext,
                   NS_STRETCH_DIRECTION_VERTICAL, 
                   contSize, radicalSize,
                   NS_STRETCH_LARGER,
                   StyleVisibility()->mDirection);
  // radicalSize have changed at this point, and should match with
  // the bounding metrics of the char
  mSqrChar.GetBoundingMetrics(bmSqr);

  // Update the desired size for the container (like msqrt, index is not yet included)
  // the baseline will be that of the base.
  mBoundingMetrics.ascent = bmBase.ascent + psi + ruleThickness;
  mBoundingMetrics.descent = 
    std::max(bmBase.descent,
           (bmSqr.ascent + bmSqr.descent - mBoundingMetrics.ascent));
  mBoundingMetrics.width = bmSqr.width + bmBase.width;
  mBoundingMetrics.leftBearing = bmSqr.leftBearing;
  mBoundingMetrics.rightBearing = bmSqr.width + 
    std::max(bmBase.width, bmBase.rightBearing); // take also care of the rule

  aDesiredSize.SetTopAscent(mBoundingMetrics.ascent + leading);
  aDesiredSize.Height() = aDesiredSize.TopAscent() +
    std::max(baseSize.Height() - baseSize.TopAscent(),
           mBoundingMetrics.descent + ruleThickness);
  aDesiredSize.Width() = mBoundingMetrics.width;

  /////////////
  // Re-adjust the desired size to include the index.
  
  // the index is raised by some fraction of the height
  // of the radical, see \mroot macro in App. B, TexBook
  nscoord raiseIndexDelta = NSToCoordRound(0.6f * (bmSqr.ascent + bmSqr.descent));
  nscoord indexRaisedAscent = mBoundingMetrics.ascent // top of radical 
    - (bmSqr.ascent + bmSqr.descent) // to bottom of radical
    + raiseIndexDelta + bmIndex.ascent + bmIndex.descent; // to top of raised index

  nscoord indexClearance = 0;
  if (mBoundingMetrics.ascent < indexRaisedAscent) {
    indexClearance = 
      indexRaisedAscent - mBoundingMetrics.ascent; // excess gap introduced by a tall index 
    mBoundingMetrics.ascent = indexRaisedAscent;
    nscoord descent = aDesiredSize.Height() - aDesiredSize.TopAscent();
    aDesiredSize.SetTopAscent(mBoundingMetrics.ascent + leading);
    aDesiredSize.Height() = aDesiredSize.TopAscent() + descent;
  }

  nscoord dxIndex, dxSqr;
  GetRadicalXOffsets(bmIndex.width, bmSqr.width, fm, &dxIndex, &dxSqr);

  mBoundingMetrics.width = dxSqr + bmSqr.width + bmBase.width;
  mBoundingMetrics.leftBearing = 
    std::min(dxIndex + bmIndex.leftBearing, dxSqr + bmSqr.leftBearing);
  mBoundingMetrics.rightBearing = dxSqr + bmSqr.width +
    std::max(bmBase.width, bmBase.rightBearing);

  aDesiredSize.Width() = mBoundingMetrics.width;
  aDesiredSize.mBoundingMetrics = mBoundingMetrics;
  GatherAndStoreOverflow(&aDesiredSize);

  // place the index
  nscoord dx = dxIndex;
  nscoord dy = aDesiredSize.TopAscent() - (indexRaisedAscent + indexSize.TopAscent() - bmIndex.ascent);
  FinishReflowChild(indexFrame, aPresContext, indexSize, nullptr,
                    MirrorIfRTL(aDesiredSize.Width(), indexSize.Width(), dx),
                    dy, 0);

  // place the radical symbol and the radical bar
  dx = dxSqr;
  dy = indexClearance + leading; // leave a leading at the top
  mSqrChar.SetRect(nsRect(MirrorIfRTL(aDesiredSize.Width(), bmSqr.width, dx),
                          dy, bmSqr.width, bmSqr.ascent + bmSqr.descent));
  dx += bmSqr.width;
  mBarRect.SetRect(MirrorIfRTL(aDesiredSize.Width(), bmBase.width, dx),
                   dy, bmBase.width, ruleThickness);

  // place the base
  dy = aDesiredSize.TopAscent() - baseSize.TopAscent();
  FinishReflowChild(baseFrame, aPresContext, baseSize, nullptr,
                    MirrorIfRTL(aDesiredSize.Width(), baseSize.Width(), dx),
                    dy, 0);

  mReference.x = 0;
  mReference.y = aDesiredSize.TopAscent();

  aStatus = NS_FRAME_COMPLETE;
  NS_FRAME_SET_TRUNCATION(aStatus, aReflowState, aDesiredSize);
  return NS_OK;
}
Beispiel #6
0
void Grid::identifyPoints() {

	// clear lists:
	filterMap_i2g.clear();
	filterMap_g2i.clear();

	// prepare:
	MultiIndexed::IndexSetSet identical;
	vector<COORD_CART> checked;
	vector<int> checked_i;
	vector<COORD_CART> doubles;
	int duplicates = 0;
	int actLabel = 0;

	// loop:
	for (unsigned int i = 0; i < indexSize(); i++) {

		// current index set:
		MultiIndexed::IndexSet is = i2x(i);

		// get Cartesian point:
		COORD_CART cp = getPoint(is);

		// check if this has been found before:
		vector<COORD_CART>::iterator bef = find(checked.begin(), checked.end(),
				cp);

		// yes, this is a duplicate:
		if (bef != checked.end()) {

			// the old label:
			int i_old = 0;

			// search the original:
			vector<COORD_CART>::iterator found = find(doubles.begin(),
					doubles.end(), cp);

			// yes, found it:
			if (found != doubles.end()) {

				// get position:
				int pos = found - doubles.begin();
				i_old = (identical[pos])[0];

				// write:
				identical[pos].push_back(i);

				// tell:
				cout << gridName << ": Found duplicate. Identify ("
						<< String(is) << ") with (" << String(i2x(i_old))
						<< ")." << endl;

				// this reduces the grid size, so count:
				duplicates++;

			}

			// no, it's new:
			else {

				// add to lists:
				doubles.push_back(cp);
				i_old = bef - checked.begin();
				MultiIndexed::IndexSet newpair(2);
				newpair[0] = i_old;
				newpair[1] = i;
				identical.push_back(newpair);

				// tell:
				cout << gridName << ": Found duplicate. Identify ("
						<< String(is) << ") with (" << String(i2x(
						(identical.back())[0])) << ")" << endl;

				// this reduces the grid size, so count:
				duplicates++;

			}

			// write original label to filter:
			filterMap_i2g.push_back(i_old);

		}

		// no, this is not a duplicate:
		else {

			// give label:
			filterMap_i2g.push_back(actLabel);
			filterMap_g2i.push_back(i);
			actLabel++;

			// mark as checked:
			checked.push_back(cp);
			checked_i.push_back(i);

		}

	}

	// reduce grid size:
	gSize -= duplicates;

	cout<<"i2gMap: " << endl;
	cout<<String(filterMap_i2g)<<endl;
	cout<<"g2iMap: " << endl;
	cout<<String(filterMap_g2i)<<endl;

	cout << gridName << ": Index size = " << indexSize() << ", grid size = "
			<< gridSize() << endl;

}
Beispiel #7
0
vector<IO::OFILE::Data> Grid::getOData(const string & type) const {

	vector<IO::OFILE::Data> out;

	////////////////////////////////////////////////////////////
	//
	// 		Text file output:
	//
	if (type.compare(IO::OFILE::TYPE::TXT) == 0) {

		// add a piece of data: points
		IO::OFILE::Data dat;

		// set pre and post fields:
		dat.type = type;
		dat.origin = gridName;

		// Output Cartesian points:
		if (flag_output_cart) {

			dat.name = "grid_points_cartesian";
			dat.pre_data = "// " + gridName + ": " + String(gSize)
					+ " points in Cartesian space (" + String(getN()) + ")\n";

			for (unsigned int g = 0; g < gridSize(); ++g) {

				// pick a coordinate:
				const MultiIndexed::IndexSet coord = g2x(g);

				// get Cartesian coordinate:
				COORD_GRID x = getPoint(coord);

				// write:
				dat.data += String(x) + "   ";

			}

		}

		// grid point output:
		else {

			dat.name = "grid_points";
			dat.pre_data = "// " + gridName + ": " + String(indexSize())
					+ " points in grid space (" + String(getN()) + ")\n";

			for (unsigned int i = 0; i < indexSize(); i++) {

				// pick a coordinate:
				MultiIndexed::IndexSet coord = i2x(i);

				// get Cartesian coordinate:
				COORD_GRID x = getGridPoint(coord);

				// write:
				dat.data += String(x) + "   ";

			}

		}

		// write points:
		dat.data += "\n";
		out.push_back(dat);

	}

	////////////////////////////////////////////////////////////
	//
	// 		VTK ascii file output:
	//
	else if (type.compare(IO::OFILE::TYPE::VTK_ASCII) == 0) {

		// add a piece of data: points
		IO::OFILE::Data dat;

		// set pre and post fields:
		dat.type = type;
		dat.origin = gridName;

		// Output Cartesian points:
		if (flag_output_cart) {

			// meta data for grid points:
			vector<int> dims = getN();
			dims.resize(3, 1);
			dat.name = "grid_points_cartesian";
			dat.pre_data = String("DATASET UNSTRUCTURED_GRID\n")
				//	+ "DIMENSIONS " + IO::vi2s(dims) + "\n"
					+ "POINTS " + String(gridSize()) + " \n";

			for (unsigned int g = 0; g < gridSize(); g++) {

				// pick a coordinate:
				MultiIndexed::IndexSet coord = g2x(g);

				// get Cartesian coordinate:
				COORD_GRID x = getPoint(coord);

				// vtk expects 3 dimensions:
				x.resize(3, 0);

				// write:
				dat.data += String(x) + "   ";

			}

		}

		// grid point output:
		else {

			// meta data for grid points:
			vector<int> dims = getN();
			dims.resize(3, 1);
			dat.name = "grid_points";
			dat.pre_data = String("DATASET STRUCTURED_GRID\n")
					+ "DIMENSIONS " + String(dims) + "\n"
					+ "POINTS " + String(indexSize()) + " \n";

			for (unsigned int i = 0; i < indexSize(); i++) {

				// pick a coordinate:
				MultiIndexed::IndexSet coord = i2x(i);

				// get Cartesian coordinate:
				COORD_GRID x = getPoint(coord);

				// vtk expects 3 dimensions:
				x.resize(3, 0);

				// write:
				dat.data += String(x) + "   ";

			}

		}

		// write points:
		dat.data += "\n";
		out.push_back(dat);

		// add new piece of data: cells
		dat = IO::OFILE::Data();

		// set pre and post fields:
		dat.type = type;
		dat.origin = gridName;
		dat.pre_data = "CELLS " + String(cells()) + " ";
		dat.data = "";

		// Output in Cartesian space:
		if (flag_output_cart) {

			dat.name = "grid_cells_cartesian";

			// count data output:
			int dcounter = 0;

			// cell output:
			for(int i = 0; i < cells(); i++) {

				// get cell:
				MultiIndexed::IndexCell cell = getIndexCell(i);

				// grid filter:
				for(unsigned j = 0; j < cell.size(); j++)
					cell[j] = filter_i2g(cell[j]);
				reduceDup_v(cell);

				// write cell:
				dat.data += String(cell.size());
				dcounter++;
				for(unsigned j = 0; j < cell.size(); j++){
					cout<<String(cell[j])<<" -> "<<String(x2g(cell[j]))<<endl;
					dat.data += " " + String(x2g(cell[j]));
					dcounter++;
				}
				cout<<endl;
				dat.data += "\n";

			}

			dat.pre_data += String(dcounter) + "\n";

		}

		dat.data += "\n";
		out.push_back(dat);

	}

	return out;

}