const std::vector<unsigned int> gl_retained_mesh::add_faces( const std::vector<unsigned int>& faceIndices ) {
	unsigned int currIndex = 0, currFace = m_numFaces;
	std::vector< std::vector<unsigned int> > toAdd;
	std::vector<unsigned int> addedFaces;

	// Go through each face
	while( currIndex < faceIndices.size() ) {
		const unsigned int numIndicesForFace = num_verts_for_next_face( currFace );
		std::vector<unsigned int> indices( numIndicesForFace );

		if( numIndicesForFace > static_cast<unsigned int>( faceIndices.size() ) - currIndex )
			throw std::exception( "gl_retained_mesh.add_faces: Failed to add faces because incorrect number of indices were found in faceIndices parameter." );

		memcpy( &indices[0], &faceIndices[currIndex], numIndicesForFace * sizeof( unsigned int ) );

		check_face( indices );

		currIndex += numIndicesForFace;
		++currFace;
		toAdd.push_back( indices );
	}

	// Add the faces to mesh
	for( std::vector< std::vector<unsigned int> >::const_iterator it = toAdd.begin(); it != toAdd.end(); ++it ) {
		addedFaces.push_back( m_numFaces );

		insert_face( *it );
	}

	return addedFaces;
}
BitmapRef FTFont::Glyph(char32_t glyph) {
	if(!check_face()) {
		return Font::Default()->Glyph(glyph);
	}

	if (FT_Load_Char(face_.get(), glyph, FT_LOAD_NO_BITMAP) != FT_Err_Ok) {
		Output::Error("Couldn't load FreeType character %d", glyph);
	}

    if (FT_Render_Glyph(face_->glyph, FT_RENDER_MODE_MONO) != FT_Err_Ok) {
		Output::Error("Couldn't render FreeType character %d", glyph);
	}

	FT_Bitmap const& ft_bitmap = face_->glyph->bitmap;
	assert(face_->glyph->bitmap.pixel_mode == FT_PIXEL_MODE_MONO);

	size_t const pitch = std::abs(ft_bitmap.pitch);
	int const width = ft_bitmap.width;
	int const height = ft_bitmap.rows;

	BitmapRef bm = Bitmap::Create(nullptr, width, height, 0, DynamicFormat(8,8,0,8,0,8,0,8,0,PF::Alpha));
	uint8_t* data = reinterpret_cast<uint8_t*>(bm->pixels());
	int dst_pitch = bm->pitch();

	for(int row = 0; row < height; ++row) {
		for(int col = 0; col < width; ++col) {
			unsigned c = ft_bitmap.buffer[pitch * row + (col/8)];
			unsigned bit = 7 - (col%8);
			data[row * dst_pitch + col] = (c & (0x01 << bit)) ? 255 : 0;
		}
	}

	return bm;
}
Esempio n. 3
0
void FTFont::Render(Bitmap& bmp, int const x, int const y, Color const& color, unsigned const glyph) {
	if(!check_face()) {
		Font::Default()->Render(bmp, x, y, color, glyph);
		return;
	}

	if (FT_Load_Char(face_.get(), glyph, FT_LOAD_NO_BITMAP) != FT_Err_Ok) {
		Output::Error("Couldn't load FreeType character %d\n", glyph);
		return;
	}

    if (FT_Render_Glyph(face_->glyph, FT_RENDER_MODE_MONO) != FT_Err_Ok) {
		Output::Error("Couldn't render FreeType character %d\n", glyph);
		return;
	}

	FT_Bitmap const& ft_bitmap = face_->glyph->bitmap;
	assert(face_->glyph->bitmap.pixel_mode == FT_PIXEL_MODE_MONO);

	size_t const pitch = std::abs(ft_bitmap.pitch);

	for(int row = 0; row < ft_bitmap.rows; ++row) {
		for(size_t col = 0; col < pitch; ++col) {
			unsigned c = ft_bitmap.buffer[pitch * row + col];
			for(int bit = 7; bit >= 0; --bit) {
				if(c & (0x01 << bit)) {
					bmp.SetPixel(x + col * 8 + (7 - bit), y + row, color);
				}
			}
		}
	}
}
Esempio n. 4
0
int main()
{

	int itr;
	int nCount;		/* 문제의 테스트 케이스 */

	scanf("%d", &nCount);	/* 테스트 케이스 입력 */

	for (itr = 0; itr < nCount; itr++)
	{
		printf("#testcase%d\n", itr + 1);
		scanf("%d %d\n", &row, &col);
		for (int i = 0; i < row; i++){
			for (int j = 0; j < col; j++){
				scanf("%c", &table[i][j]);
			}
			getchar();
		}

		//count face
		for (int i = 0; i < row - 1; i++){
			for (int j = 0; j < col - 1; j++){
				cnt += check_face(i, j);
			}
		}
		printf("%d\n", cnt);
		init();
	}

	return 0;
}
Esempio n. 5
0
int is_solved() {
    if (!check_face(U)) return 0;
    if (!check_face(D)) return 0;
    if (!check_face(L)) return 0;
    if (!check_face(R)) return 0;
    if (!check_face(F)) return 0;
    if (!check_face(B)) return 0;
    return 1;
}
const unsigned int gl_retained_mesh::add_face( const std::vector<unsigned int>& faceIndices ) {
	std::vector<unsigned int> indices( 0 );
	unsigned int faceNumber = m_numFaces;
	
	// Throw an exception if the incorrect number of faces are passed as the parameter. There are two cases:
	//   1) If there are currently no faces in the mesh, throw an exception if the number of indices passed is not the correct number of 
	//		indices for the first face.
	//   2) If there are currently faces in the mesh, throw an exception if the number of indices passed is not the correct number of indices
	//		for each subsequent face.
	if( ( m_indices.size() == 0 &&  faceIndices.size() != get_num_verts_for_init_face( m_primitiveType )  ) 
		|| ( m_indices.size() != 0 && faceIndices.size() != get_num_verts_for_next_face( m_primitiveType ) ) ) {
		throw std::runtime_error( "gl_retained_mesh.add_faces: Failed to add faces to the mesh because an incorrect number of indices(" + 
			boost::lexical_cast<std::string>( faceIndices.size() ) + ") where passed to the function." );
	}

	check_face( faceIndices );
	insert_face( faceIndices );

	return faceNumber;
}
Esempio n. 7
0
void velocity_solver_init_stokes (double const* levelsRatio_F)
{
  int verb = 1;

  // set velocity 0
  velocityOnVertices.resize (2 * nVertices * (nLayers + 1), 0.);
  velocityOnCells.resize (2 * nCells_F * (nLayers + 1), 0.);

  //
  // interface to phg
  //
  printf ("* Init full stokes?\n");
  if (isDomainEmpty)
  {
    return;
  }

  layersRatio.resize (nLayers);
  // !!Indexing of layers is reversed
  for (UInt i = 0; i < nLayers; i++)
  {
    layersRatio[i] = levelsRatio_F[nLayers - 1 - i];
  }
  //std::copy(levelsRatio_F, levelsRatio_F+nLayers, layersRatio.begin());

  mapCellsToVertices (velocityOnCells, velocityOnVertices, 2, nLayers, LayerWise);

  printf ("* Init full stokes.\n");
  //
  // Output 3D mesh
  //
  RegionMesh<LinearTetra>& mesh = * (iceProblemPtr->mesh3DPtr);
  unsigned int numVertices = mesh.numVertices();
  unsigned int numElements = mesh.numElements();

  std::vector<double > coord (3 * numVertices);

  TET* tet;
  tet = (TET*) calloc (numElements, sizeof (*tet) );

  // update faces
  mesh.updateElementFaces();
  //if (verb > 0) printf("has local face :%d\n", mesh.hasLocalFaces());

  // Num of verts (local, global)
  if (verb > 0) printf ("nvert:%5d, nvert_global:%5d\n",
      mesh.numVertices(), mesh.numGlobalVertices() );

  // Num of elements (local, global)
  if (verb > 0) printf ("nedge:%5d, nedge_global:%5d\n",
      mesh.numElements(), mesh.numGlobalElements() );

  if (verb > 0) printf ("nface:%5d, nface_global:%5d\n",
      mesh.numFaces(), mesh.numGlobalFaces() );

  if (verb > 0) printf ("nelem:%5d, nelem_global:%5d\n",
      mesh.numElements(), mesh.numGlobalElements() );

  //
  // Element:
  //
  // verts[4] (local)
  // bdry_type[4]
  // neigh[4]
  //
  for (unsigned int i = 0; i < numElements; i++)
  {
    if (verb > 1)
    {
      printf ("elem: %d\n", i);
    }
    for (unsigned int j = 0; j < 4; j++)
    {
      const double* c = &mesh.element (i).point (j).coordinates() [0];
      if (verb > 1) printf ("   vert: (%16.8f, %16.8f, %16.8f) %5d %5d\n",
          c[0], c[1], c[2],
          mesh.element (i).point (j).localId(),
          mesh.element (i).point (j).id() //global Id
      );
      int vert = mesh.element (i).point (j).localId();
      tet[i].verts[j] = vert;
      coord[vert * 3 ] = c[0];
      coord[vert * 3 + 1] = c[1];
      coord[vert * 3 + 2] = c[2];
    }

    for (unsigned int j = 0; j < 4; j++)
    {

      //  Life tet face (ElementShapes)
      //  0, 2, 1,
      //  0, 1, 3,
      //  1, 2, 3,
      //  0, 3, 2
      //
      //  PHG tet face (utils.c)
      //  1, 2, 3,
      //  0, 2, 3,
      //  0, 1, 3,
      //  0, 1, 2
      //
      //  map Life to PHG
      //  3, 2, 0, 1
      //  reverse
      //  2, 3, 1, 0
      //
      if (verb > 1)
      {
        check_face (mesh, i, j);
      }

      int faceId = mesh.localFaceId (i, j);
      if (verb > 1)
      {
        printf (" faceId %d\n", faceId);
      }
      assert ( (ID) faceId != NotAnId);
      static int map_[4] = {3, 2, 0, 1};

      RegionMesh<LinearTetra>::face_Type& face
      = mesh.face (faceId);

      ID vol0, vol1;
      ID pos0, pos1;
      vol0 = face.firstAdjacentElementIdentity();
      pos0 = face.firstAdjacentElementPosition();
      vol1 = face.secondAdjacentElementIdentity();
      pos1 = face.secondAdjacentElementPosition();

      //
      // bound_type: 1. interior(local), 2.interior(remote), [3|4|5].bdry
      //
      if (face.flag() & EntityFlags::PHYSICAL_BOUNDARY)
      {
        assert (vol0 == i);
        assert (pos0 == j);
        assert (vol1 == NotAnId);
        assert (pos1 == NotAnId);

        //
        // lower face: 1; upper face 2,
        //    pass as: 3(low), 4(up), 5(lateral, other)
        // Note: marker comes from mpas
        //
        unsigned int lowerSurfaceMarker = 1;
        unsigned int upperSurfaceMarker = 2;

        tet[i].neighbours[map_[j]] = -1;
        if (face.markerID() == lowerSurfaceMarker)
        {
          tet[i].bound_type[map_[j]] = 3;
        }
        else if (face.markerID() == upperSurfaceMarker)
        {
          tet[i].bound_type[map_[j]] = 4;
        }
        else
        {
          tet[i].bound_type[map_[j]] = 5;
        }

      }
      else if (face.flag() & EntityFlags::SUBDOMAIN_INTERFACE)
      {
        assert (vol0 == i);
        assert (pos0 == j);
        assert (vol1 == NotAnId);
        assert (pos1 == NotAnId);

        tet[i].neighbours[map_[j]] = -1;
        tet[i].bound_type[map_[j]] = 2;
      }
      else
      {
        if (vol0 == i)
        {
          assert (pos0 == j);
          tet[i].neighbours[map_[j]] = vol1;
          tet[i].bound_type[map_[j]] = 1;
        }
        else if (vol1 == i)
        {
          assert (pos1 == j);
          tet[i].neighbours[map_[j]] = vol0;
          tet[i].bound_type[map_[j]] = 1;
        }
        else
        {
          abort();
        }
      }
    }
  }

  // L2G map vert
  std::vector<int > L2Gmap_vert (numVertices);
  for (unsigned int i = 0; i < numVertices; i++)
  {
    L2Gmap_vert[i] = mesh.point (i).id();
    if (verb > 1) printf ("  L2G vert: %5d %5d\n", i,
        mesh.point (i).id() );
  }

  // L2G map elem
  std::vector<int > L2Gmap_elem (numElements);
  for (unsigned int i = 0; i < numElements; i++)
  {
    L2Gmap_elem[i] = mesh.element (i).id();
    if (verb > 1) printf ("  L2G elem: %5d %5d\n", i,
        mesh.element (i).id() );
  }

  // if (verb > 0) printf("check all face\n");
  // for (unsigned int i = 0; i < numFaces; i++) {
  //  check_face(mesh, i);
  // }

  printf ("  Call PHG\n");
  phgGrid = phgImportParallelGrid (phgGrid,// old grid
      numVertices,
      numElements,
      mesh.numGlobalVertices(),
      mesh.numGlobalElements(),
      &L2Gmap_vert[0],
      &L2Gmap_elem[0],
      &coord[0],
      tet,
      reducedComm
  );

  return;
}