Example #1
0
inline void load(
    Archive & ar,
    STD::vector<bool, Allocator> &t,
    const unsigned int /* file_version */
){
    // retrieve number of elements
    unsigned int count;
    ar >> BOOST_SERIALIZATION_NVP(count);
    t.clear();
    while(count-- > 0){
        bool i;
        ar >> boost::serialization::make_nvp("item", i);
        t.push_back(i);
    }
}
void PlayerQuestObject::getTasks( std::vector<Unicode::String> &taskVector)
{
	taskVector.clear();
	for(std::vector<Unicode::String>::size_type i = 0; i < m_tasks.get().size(); ++i)
		taskVector.push_back(m_tasks.get()[i]);
}
bool CEGLNativeTypeRaspberryPI::ProbeResolutions(std::vector<RESOLUTION_INFO> &resolutions)
{
#if defined(TARGET_RASPBERRY_PI)
  resolutions.clear();
  m_res.clear();

  if(!m_DllBcmHost)
    return false;

  m_fixedMode               = false;

  /* read initial desktop resolution before probe resolutions.
   * probing will replace the desktop resolution when it finds the same one.
   * we raplace it because probing will generate more detailed 
   * resolution flags we don't get with vc_tv_get_state.
   */

  if(m_initDesktopRes)
  {
    TV_GET_STATE_RESP_T tv_state;

    // get current display settings state
    memset(&tv_state, 0, sizeof(TV_GET_STATE_RESP_T));
    m_DllBcmHost->vc_tv_get_state(&tv_state);

    m_desktopRes.iScreen      = 0;
    m_desktopRes.bFullScreen  = true;
    m_desktopRes.iWidth       = tv_state.width;
    m_desktopRes.iHeight      = tv_state.height;
    m_desktopRes.iScreenWidth = tv_state.width;
    m_desktopRes.iScreenHeight= tv_state.height;
    m_desktopRes.dwFlags      = tv_state.scan_mode ? D3DPRESENTFLAG_INTERLACED : D3DPRESENTFLAG_PROGRESSIVE;
    m_desktopRes.fRefreshRate = (float)tv_state.frame_rate;
    m_desktopRes.strMode.Format("%dx%d", tv_state.width, tv_state.height);
    if((float)tv_state.frame_rate > 1)
    {
        m_desktopRes.strMode.Format("%s @ %.2f%s - Full Screen", m_desktopRes.strMode, (float)tv_state.frame_rate,
            m_desktopRes.dwFlags & D3DPRESENTFLAG_INTERLACED ? "i" : "");
    }
    m_initDesktopRes = false;

    int gui_width  = m_desktopRes.iWidth;
    int gui_height = m_desktopRes.iHeight;

    ClampToGUIDisplayLimits(gui_width, gui_height);

    m_desktopRes.iWidth = gui_width;
    m_desktopRes.iHeight = gui_height;

    m_desktopRes.iSubtitles   = (int)(0.965 * m_desktopRes.iHeight);

    CLog::Log(LOGDEBUG, "EGL initial desktop resolution %s\n", m_desktopRes.strMode.c_str());
  }


  GetSupportedModes(HDMI_RES_GROUP_CEA, resolutions);
  GetSupportedModes(HDMI_RES_GROUP_DMT, resolutions);
  GetSupportedModes(HDMI_RES_GROUP_CEA_3D, resolutions);

  if(resolutions.size() == 0)
  {
    TV_GET_STATE_RESP_T tv;
    m_DllBcmHost->vc_tv_get_state(&tv);

    RESOLUTION_INFO res;
    CLog::Log(LOGDEBUG, "EGL probe resolution %dx%d@%f %s:%x\n",
        m_desktopRes.iWidth, m_desktopRes.iHeight, m_desktopRes.fRefreshRate,
        m_desktopRes.dwFlags & D3DPRESENTFLAG_INTERLACED ? "i" : "p");

    m_res.push_back(m_desktopRes);
    resolutions.push_back(m_desktopRes);
  }

  if(resolutions.size() < 2)
    m_fixedMode = true;

  DLOG("CEGLNativeTypeRaspberryPI::ProbeResolutions\n");
  return true;
#else
  return false;
#endif
}
Example #4
0
bool readOBJFile(const std::string &filename, Mesh * _mesh, Scene * _scene, bool & _readVertexNormals,	std::vector<Vector3 * >& vertexNormalList ,bool & _readTexture) {

	std::vector<Vector2 * > vertexTextureList;
	vertexNormalList.clear();
	vertexTextureList.clear();
  // Load the mesh.  This routine supports a simplified version of the
  // .obj file format.  Lines begin with either '#' to indicate a comment,
  // 'v' to indicate a vertex, or 'f' to indicat a face.  Comments are
  // ignored.  ** Vertex indices (in 'f' lines) are one based, so they 
  // start with one and not zero. **  Faces can only have three indices --
  // so they must be triangles.  Any other tag in the file is ignored.

  printf("Loading mesh \"%s\".\n", filename.c_str());

  // Load a simplified version of the .obj file format.

  // Open the file.
  FILE *stream = fopen(filename.c_str(), "r");
  
  if (stream == NULL) {
    printf("Error opening file \"%s\" for reading.\n", filename.c_str());
    return false;
  }

  // Read the contents.

  bool unknownWarning = false;
  char str[256];
  double x, y, z;
	double tx,ty;
  int i0, i1, i2;
	int it0, it1, it2;
	int in0, in1, in2;
  int v;
	printf("starting\n");
  while (fscanf(stream, "%s", str) == 1) {

    if (str[0] == '#') {

      // Comment
      // Read until the next newline.
      
      while (1) {
        char c;
        v = fscanf(stream, "%c", &c);
        if ((c == '\n') || (v != 1))
          break;
      }
      v=1;

    } else if (strcmp(str, "vn") == 0) {
 /*     while (1) {
        char c;
        v = fscanf(stream, "%c", &c);
        if ((c == '\n') || (v != 1))
          break;
      }*/
	
	
	  double nx, ny, nz;
      v = fscanf(stream, "%lf", &nx);
      v = fscanf(stream, "%lf", &ny);
      v = fscanf(stream, "%lf", &nz);
			Vector3 * newNormal = new Vector3(nx, ny, nz);
			newNormal->normalize();
			vertexNormalList.push_back(newNormal);

    } else if (strcmp(str, "vt") == 0) {
      
      v = fscanf(stream, "%lf", &tx);
      v = fscanf(stream, "%lf", &ty);
			Vector2 * newTexture = new Vector2(tx, ty);
			vertexTextureList.push_back(newTexture);

    }else if (strcmp(str, "v") == 0) {
      
      // Vertex
      // Read three doubles and add the vertex.

      v = fscanf(stream, "%lf", &x);
      v = fscanf(stream, "%lf", &y);
      v = fscanf(stream, "%lf", &z);
			MeshVertex *mv = new MeshVertex(Vector3(x, y, z));
      _mesh->addVertex(mv);
			//printf("x:%f,y:%f,z:%f\n",x,y,z);
    } else if (strcmp(str, "f") == 0) {
      
      // Face 
      // Read three vertex indices and add the triangle.

			char c;
      bool vts=false; 
      bool vns=false;
      i0=i1=i2=-1;
      it0=it1=it2=-1;
      in0=in1=in2=-1;

			v = fscanf(stream, "%d", &i0);
      v = fscanf(stream, "%c", &c);
      if( c=='/')
      {
        vts=true;
			  v = fscanf(stream, "%d", &it0); 
			  v = fscanf(stream, "%c", &c);
        if( c=='/' ){
          vns=true;
			    v = fscanf(stream, "%d", &in0);
        }
      }

			v = fscanf(stream, "%d", &i1);
			v = fscanf(stream, "%c", &c);
      if( c=='/')
      {
        vts=true;
			  v = fscanf(stream, "%d", &it1); 
			  v = fscanf(stream, "%c", &c);
        if( c=='/' ){
          vns=true;
			    v = fscanf(stream, "%d", &in1);
        }
      }

			v = fscanf(stream, "%d", &i2);
			v = fscanf(stream, "%c", &c);
      if( c=='/')
      {
        vts=true;
			  v = fscanf(stream, "%d", &it2); 
			  v = fscanf(stream, "%c", &c);
        if( c=='/' ){
          vns=true;
			    v = fscanf(stream, "%d", &in2);
        }
      }

      // Since the .obj file format is one-based, the indices start
      // at one rather than at zero.  So, we must subtract one from
      // each index.
      i0--; i1--; i2--;
	  it0--;it1--;it2--;
      in0--;in1--;in2--;
      
      //_triangles.push_back(Tri(i0, i1, i2));
			
    assert(i0>=0 && i1 >=0 && i2 >= 0); //checks if we have valid vertex indices
	  MeshTriangle *mt = new MeshTriangle(_mesh, _mesh->getVertex(i0),
												 _mesh->getVertex(i1),
												 _mesh->getVertex(i2));
	  if (vertexTextureList.size() > 0) {
      assert(it0>=0 && it1>=0 &&it2>=0); //checks if we have valid texture vertices
		  _mesh->getVertex(i0)->setTexture(vertexTextureList[it0]);
		  _mesh->getVertex(i1)->setTexture(vertexTextureList[it1]);
		  _mesh->getVertex(i2)->setTexture(vertexTextureList[it2]);
      _readTexture=true;
	  }
    if(vertexNormalList.size() > 0){
      assert(in0 >=0 && in1>=0 &&in2>=0);
		  _mesh->getVertex(i0)->setNormal(vertexNormalList[in0]);
		  _mesh->getVertex(i1)->setNormal(vertexNormalList[in1]);
		  _mesh->getVertex(i2)->setNormal(vertexNormalList[in2]);
      _readVertexNormals=true;
    }

	  _mesh->addTriangle(mt);
	  _scene->addElement(mt);
    v=1;


	  //printf("i0:%d,i1:%d,i2:%d\n",i0,i1,i2);

    } else {
      
      if (!unknownWarning) {
        printf("Unknown token \"%s\" encountered.  (Additional warnings surpressed.)\n", str);
        unknownWarning = true;
      }

      // Read until the next newline.
      while (1) {
        char c;
        v = fscanf(stream, "%c", &c);
        if ((c == '\n') || (v != 1))
          break;
      }
    }
    
    if (v != 1) {
      printf("Error: Premature end of file while reading \"%s\".", filename.c_str());
      return false;
    }
  }
  
  fclose(stream);
  return true;
	
}
Example #5
0
void CreateModel()
{

std::cerr << "Loading model from OFF file"  << std::endl;

    std::istream& in = std::cin;

 int nf,ne;
  char s[256];
  in >> s;
  bool noff = false;
  bool doff = false;


  if (s[0] == 'O' && s[1] == 'F' && s[2] == 'F'){
    ;
    std::cerr << "Computing new tags and deltas" <<std::endl;
  }
  else if (s[0] == 'N' && s[1] == 'O' && s[2] == 'F' && s[3] == 'F'){
    noff = true;
  }
  else if (s[0] == 'D' && s[1] == 'O' && s[2] == 'F' && s[3] == 'F'){
    doff = true;
    std::cerr << "Running with tags and deltas" <<std::endl;
  }
  else{
    std::cerr << "BAD OFF HEADER "  << std::endl;
    return;
  }

  in >> nv;
  in >> nf;
  in >> ne;

  if (nv <= 0 || nf <= 0){
    std::cerr << "number of verts or nf below zero "  << std::endl;
    return;
  }

  std::cerr << nv << " " << nf << " " << ne << std::endl;

 
  //  float Verts[12*nv];
  Verts.clear();
  Verts.resize(12*nv);

  Vec3f vmin(10e6 );
  Vec3f vmax(-10e6 );


  for (int i = 0; i < nv; ++i)
  {
    in >> Verts[i*12+0];
    in >> Verts[i*12+1];
    in >> Verts[i*12+2];
    if (doff){
      in >> Verts[i*12+3];
      in >> Verts[i*12+4];
      in >> Verts[i*12+5];

      in >> Verts[i*12+6];
      in >> Verts[i*12+7];
      in >> Verts[i*12+8];

      in >> Verts[i*12+9];
      in >> Verts[i*12+10];
      in >> Verts[i*12+11];
    }
    else{
      Verts[i*12+3] = 0.0;
      Verts[i*12+4] = 0.0;
      Verts[i*12+5] = 0.0;
      Verts[i*12+6] = 0.0;
      Verts[i*12+7] = 0.0;
      Verts[i*12+8] = 0.0;
      Verts[i*12+9] = 0.0; 
      Verts[i*12+10] = 0.0;
      Verts[i*12+11] = 0.0;
    }




    vmin[0] = std::min(Verts[i*12+0], vmin[0]);
    vmin[1] = std::min(Verts[i*12+1], vmin[1]);
    vmin[2] = std::min(Verts[i*12+2], vmin[2]);

    vmax[0] = std::max(Verts[i*12+0], vmax[0]);
    vmax[1] = std::max(Verts[i*12+1], vmax[1]);
    vmax[2] = std::max(Verts[i*12+2], vmax[2]);
  }
Example #6
0
void Grid::vector_copy(std::vector< double >& vec, std::vector< double > source) {
	vec.clear();
	for(int i = 0; i < size; i++)
		vec.push_back(source[i]);
}
Example #7
0
  void MSNumpressCoder::decodeNPInternal_(const unsigned char* in, size_t in_size, std::vector<double>& out, const NumpressConfig & config)
  {
    out.clear();
    if (in_size == 0) return;

    size_t byteCount = in_size;

#ifdef NUMPRESS_DEBUG
    std::cout << "decodeNP_: array input with length " << in_size << std::endl;
    for (int i = 0; i < in_size; i++)
    {
      std::cout << "array[" << i << "] : " << (int)in[i] << std::endl;
    }
#endif

    try
    {
      size_t initialSize;

      switch (config.np_compression)
      {
      case LINEAR:
      {
        initialSize = byteCount * 2;
        if (out.size() < initialSize) { out.resize(initialSize); }
        size_t count = numpress::MSNumpress::decodeLinear(in, byteCount, &out[0]);
        out.resize(count);
        break;
      }

      case PIC:
      {
        initialSize = byteCount * 2;
        if (out.size() < initialSize) { out.resize(initialSize); }
        size_t count = numpress::MSNumpress::decodePic(in, byteCount, &out[0]);
        out.resize(count);
        break;
      }

      case SLOF:
      {
        initialSize = byteCount / 2;
        if (out.size() < initialSize) { out.resize(initialSize); }
        size_t count = numpress::MSNumpress::decodeSlof(in, byteCount, &out[0]);
        out.resize(count);
        break;
      }

      case NONE:
      {
        return;
      }

      default:
        break;
      }

    }
    catch (...)
    {
      throw Exception::ConversionError(__FILE__, __LINE__, __PRETTY_FUNCTION__, "Error in Numpress decompression");
    }

#ifdef NUMPRESS_DEBUG
    std::cout << "decodeNP_: output size " << out.size() << std::endl;
    for (int i = 0; i < out.size(); i++)
    {
      std::cout << "array[" << i << "] : " << out[i] << std::endl;
    }
#endif


  }
 /** Reset the point cloud to an empty state. */
 void clear() { points.clear(); bbox.setNull(); }
Example #9
0
void WCNurbs::CircularPoints(const WCVector4 &center, const WCVector4 &xUnit, const WCVector4 &yUnit,
	const WPFloat &radius, const WPFloat &startAngleDeg, const WPFloat &endAngleDeg,
	std::vector<WCVector4> &controlPoints, std::vector<WPFloat> &knotPoints) {
	//Setup angle parameters
	WPFloat startAngle = (2.0 * M_PI *startAngleDeg) / 360.0;
	WPFloat endAngle = (2.0 * M_PI * endAngleDeg) / 360.0;

	//Determine some angle stuff
	if (endAngle < startAngle) endAngle = (2.0 * M_PI) + endAngle;
	WPFloat theta = endAngle - startAngle;
	WPUInt numArcs;
	if (theta <= M_PI_2) numArcs = 1;
	else if (theta <= M_PI) numArcs = 2;
	else if (theta <= (M_PI_2 + M_PI)) numArcs = 3;
	else numArcs = 4;
	WPFloat deltaTheta = theta / numArcs;
	WPUInt numControlPoints = 2 * numArcs + 1;
	WPUInt numKnotPoints = 2 * numArcs + 4;

//Try to isolate some win32 specifics
#ifdef __WIN32__
	WCVector4 points[64];
	WPFloat knots[64];
#else
	WCVector4 points[numControlPoints+1];
	WPFloat *knots = new WPFloat[numKnotPoints];
#endif
	
	
	WPFloat w1 = cos(deltaTheta / 2.0);
	WCVector4 p0 = center + (xUnit * radius * cos(startAngle)) + (yUnit * radius * sin(startAngle));
	WCVector4 t0 = (yUnit * cos(startAngle)) - (xUnit * sin(startAngle));
	points[0] = p0;
	WPUInt index = 0;
	WPFloat angle = startAngle;
	
	//Create all the control points
	WCVector4 p1, p2, t2;
	WPFloat dummy;
	for (WPUInt i=0; i<=numArcs; i++) {
		angle = angle + deltaTheta;
		p2 = center + (xUnit * radius * cos(angle)) + (yUnit * radius * sin(angle));
		points[index+2] = p2;
		t2 = (yUnit * cos(angle)) - (xUnit * sin(angle));
		RayRayIntersection(p0, t0, p2, t2, dummy, dummy, p1);
		p1.L(w1);
		points[index+1] = p1;
		index += 2;
		if (i < numArcs) {
			p0 = p2;
			t0 = t2;
		}
	}
	
	//Load knot vector
	WPUInt tmpInt = 2 * numArcs + 1;
	for (int i=0; i<3; i++) {
		knots[i] = 0.0;
		knots[i + tmpInt] = 1.0;		
	}
	switch(numArcs) {
		case 1: break;
		case 2: knots[3] = knots[4] = 0.5; break;
		case 3: knots[3] = knots[4] = 1.0 / 3.0;
				knots[5] = knots[6] = 2.0 / 3.0; break;
		case 4: knots[3] = knots[4] = 0.25;
				knots[5] = knots[6] = 0.5;
				knots[7] = knots[8] = 0.75; break;
	}

	//Make sure cp and kp are clear
	controlPoints.clear();
	knotPoints.clear();

	//Create vector of control points
	for (WPUInt i=0; i<numControlPoints; i++)
		controlPoints.push_back(points[i]);
	//Create vector of knot points
	for (WPUInt i=0; i<numKnotPoints; i++)
		knotPoints.push_back(knots[i]);

	//Delete arrays
#ifndef __WIN32__
//	delete points;
	delete knots;
#endif
}
Example #10
0
    void Reset(void) // Reset bin counts to 0
    {
	m_DimClassBins.clear();
	
	m_nDataPoints = 0;
    };
	void MaterialEditorScene::_selectMaterial()
	{
		const std::string currentDir = Directory::GetCurrentDirectory();
		const std::string absPath = Path::AbsoluteName(currentDir.c_str(), WE::EditorConfiguration::GetCookedDirectory().c_str());
		static std::vector<std::string> materialGettable;
		static std::vector<std::string> materialFullPath;
		static int counter = 0;
		++counter;
		if (counter > 20)
		{
			materialGettable.clear();
			materialFullPath.clear();

			Directory dir;
			const bool succeed = dir.open(absPath.c_str());
			AGE_ASSERT(succeed && "Impossible to open directory");
			for (auto it = dir.recursive_begin(); it != dir.recursive_end(); ++it)
			{
				if (Directory::IsFile(*it) && FileUtils::GetExtension(*it) == "mage")
				{
					materialGettable.push_back(std::string(Path::RelativeName(absPath.c_str(), *it)));
					materialFullPath.push_back(*it);
				}
			}
			dir.close();
			counter = 0;
		}

		static ImGuiTextFilter filter;
		ImGui::Text("Search");
		filter.Draw();

		ImGui::ListBoxHeader("List of existing material", size);
		for (int i = 0; i < materialFullPath.size(); ++i)
		{
			if (filter.PassFilter(materialGettable[i].c_str()))
			{
				if (ImGui::Selectable(materialGettable[i].c_str()))
				{
					_indexMaterial = i;
				}
			}
		}
		ImGui::ListBoxFooter();

		if (_indexMaterial != -1 && ImGui::Button("open a material"))
		{
			_resetEdition();

			std::shared_ptr<MaterialDataSet> material_data_set = std::make_shared<MaterialDataSet>();
			std::ifstream ifs(materialFullPath[_indexMaterial], std::ios::binary);
			cereal::PortableBinaryInputArchive ar(ifs);
			ar(*material_data_set.get());
			_current = *material_data_set;
			if (_current.name == "")
			{
				std::string fileName = std::string(materialGettable[_indexMaterial]);
				_current.name = fileName.substr(0, fileName.find('.'));
			}
			_mode = ModeMaterialEditor::selectSubMaterial;
		}
		if (_indexMaterial == -1)
		{
			ImGui::Text("Please select one material for edition");
		}
	}
static bool convertTCDArrayToVector(const class RunTimeEnvironment & rte, std::vector< TittmColumnDefinition > & sitmTCD, const std::string & sampleInfoFileName)
{

    sitmTCD.clear();

    std::stringstream msgSStr;

    size_t       numStaticDefinitions
        = sizeof(SITM_COLUMN_DEFINITIONS) / sizeof(SITM_COLUMN_DEFINITIONS[0]);

    bool         okHeaderLine = true;

    // STATIC column definitions
    for (int i = 0; i < numStaticDefinitions; i++) {

        APT_ERR_ASSERT(SITM_COLUMN_DEFINITIONS[i].m_index == i, "");
        sitmTCD.push_back(SITM_COLUMN_DEFINITIONS[i]);
        sitmTCD.back().m_ignoreRE = new pcrecpp::RE("^\\#");

    }

    // The sample info columns are dynamic and not fixed.
    // Scan the TsvFile headers and pick up all the columns.

    TsvFile tsv;

    //
    tsv.m_optAutoTrim   = true; // remove '"'s
    tsv.m_optQuoteChar1 = 0;    // ignore "'"s

    if (tsv.open(sampleInfoFileName) != TSV_OK) {
        APT_ERR_ABORT(sampleInfoFileName + ": failed opening input Tsv file.");
    }

    // DYNAMIC column definitions.
    for (int i = numStaticDefinitions; i < tsv.getColumnCount(0) ; i++) {

        std::string columnName;

        if (tsv.cidx2cname(0, i, columnName) == TSV_OK) {

            TittmColumnDefinition sampleTCD = SAMPLE_INFO_COLUMN_TEMPLATE;
            sampleTCD.m_index = i;
            sampleTCD.m_columnName = columnName;
            sitmTCD.push_back(sampleTCD);

        } // if the tsv file parsed ok
        else {
            APT_ERR_ABORT("tsv.cidx2cname returned unexpected error");
        } // if there was a TSV_ERROR


    } // for each column, append it to the column definitions.

    if (sitmTCD.size() == numStaticDefinitions) {
        okHeaderLine = false;
        msgSStr << sampleInfoFileName << ": invalid TsvFile header first-line, ";
        msgSStr << "no columns found." << endl;

    }

    tsv.close();

    if (!okHeaderLine) {
        if (sitmTCD.size() > 5) {
            Verbose::out(ADT_VERBOSE_NORMAL, msgSStr.str(), false);
        } else {
            Verbose::out(ADT_VERBOSE_NORMAL, sampleInfoFileName + ": invalid TsvFile is missing the header line.", false);
        }
    }

    return okHeaderLine;

}
Example #13
0
		bool TLDDetector::ocl_detect(const Mat& img, const Mat& imgBlurred, Rect2d& res, std::vector<LabeledPatch>& patches, Size initSize)
		{
			patches.clear();
			Mat_<uchar> standardPatch(STANDARD_PATCH_SIZE, STANDARD_PATCH_SIZE);
			Mat tmp;
			int dx = initSize.width / 10, dy = initSize.height / 10;
			Size2d size = img.size();
			double scale = 1.0;
			int npos = 0, nneg = 0;
			double maxSc = -5.0;
			Rect2d maxScRect;
			int scaleID;
			std::vector <Mat> resized_imgs, blurred_imgs;
			std::vector <Point> varBuffer, ensBuffer;
			std::vector <int> varScaleIDs, ensScaleIDs;

			//Detection part
			//Generate windows and filter by variance
			scaleID = 0;
			resized_imgs.push_back(img);
			blurred_imgs.push_back(imgBlurred);
			do
			{
				Mat_<double> intImgP, intImgP2;
				computeIntegralImages(resized_imgs[scaleID], intImgP, intImgP2);
				for (int i = 0, imax = cvFloor((0.0 + resized_imgs[scaleID].cols - initSize.width) / dx); i < imax; i++)
				{
					for (int j = 0, jmax = cvFloor((0.0 + resized_imgs[scaleID].rows - initSize.height) / dy); j < jmax; j++)
					{
						if (!patchVariance(intImgP, intImgP2, originalVariancePtr, Point(dx * i, dy * j), initSize))
							continue;
						varBuffer.push_back(Point(dx * i, dy * j));
						varScaleIDs.push_back(scaleID);
					}
				}
				scaleID++;
				size.width /= SCALE_STEP;
				size.height /= SCALE_STEP;
				scale *= SCALE_STEP;
				resize(img, tmp, size, 0, 0, DOWNSCALE_MODE);
				resized_imgs.push_back(tmp);
				GaussianBlur(resized_imgs[scaleID], tmp, GaussBlurKernelSize, 0.0f);
				blurred_imgs.push_back(tmp);
			} while (size.width >= initSize.width && size.height >= initSize.height);

			//Encsemble classification
			for (int i = 0; i < (int)varBuffer.size(); i++)
			{
				prepareClassifiers((int)blurred_imgs[varScaleIDs[i]].step[0]);
				if (ensembleClassifierNum(&blurred_imgs[varScaleIDs[i]].at<uchar>(varBuffer[i].y, varBuffer[i].x)) <= ENSEMBLE_THRESHOLD)
					continue;
				ensBuffer.push_back(varBuffer[i]);
				ensScaleIDs.push_back(varScaleIDs[i]);
			}

			//NN classification
			//Prepare batch of patches
			int numOfPatches = (int)ensBuffer.size();
			Mat_<uchar> stdPatches(numOfPatches, 225);
			double *resultSr = new double[numOfPatches];
			double *resultSc = new double[numOfPatches];

			uchar *patchesData = stdPatches.data;
			for (int i = 0; i < (int)ensBuffer.size(); i++)
			{
				resample(resized_imgs[ensScaleIDs[i]], Rect2d(ensBuffer[i], initSize), standardPatch);
				uchar *stdPatchData = standardPatch.data;
				for (int j = 0; j < 225; j++)
					patchesData[225*i+j] = stdPatchData[j];
			}
			//Calculate Sr and Sc batches
			ocl_batchSrSc(stdPatches, resultSr, resultSc, numOfPatches);


			for (int i = 0; i < (int)ensBuffer.size(); i++)
			{
				LabeledPatch labPatch;
				standardPatch.data = &stdPatches.data[225 * i];
				double curScale = pow(SCALE_STEP, ensScaleIDs[i]);
				labPatch.rect = Rect2d(ensBuffer[i].x*curScale, ensBuffer[i].y*curScale, initSize.width * curScale, initSize.height * curScale);

				double srValue, scValue;

				srValue = resultSr[i];

				////To fix: Check the paper, probably this cause wrong learning
				//
				labPatch.isObject = srValue > THETA_NN;
				labPatch.shouldBeIntegrated = abs(srValue - THETA_NN) < 0.1;
				patches.push_back(labPatch);
				//

				if (!labPatch.isObject)
				{
					nneg++;
					continue;
				}
				else
				{
					npos++;
				}
				scValue = resultSc[i];
				if (scValue > maxSc)
				{
					maxSc = scValue;
					maxScRect = labPatch.rect;
				}
			}

			if (maxSc < 0)
				return false;
			res = maxScRect;
			return true;
		}
Example #14
0
	inline void clear_message (void) { _message.clear(); }
Example #15
0
	// Draw the item list window
	//
	int List_Window::draw(window_info *win)
	{
		Vars::lists()->check_and_timed_save(false);

		// if resizing wait until we stop
		if (win->resized)
			resizing = true;
		// once we stop, snap the window size to fix nicely
		else if (resizing)
		{
			calc_num_show_names(win->len_y);
			resizing = false;
			resize_window (win->window_id, get_size_x(), get_size_y());
		}

		// check if we need to change the number of grid rows shown
		int new_num_grid_rows = min_grid_rows();
		if (Vars::lists()->valid_active_list())
			new_num_grid_rows = std::max(static_cast<size_t>(new_num_grid_rows), (Vars::lists()->get_list().get_num_items() +5) / 6);
		if (num_grid_rows != new_num_grid_rows)
		{
			num_grid_rows = new_num_grid_rows;
			resized_name_panel(win);
		}

		// if the left/right position flag has changed, restore the window to its default location
		if (last_items_list_on_left != items_list_on_left)
		{
			if (last_items_list_on_left != -1)
				reset_position();
			last_items_list_on_left = items_list_on_left;
		}

		glEnable(GL_TEXTURE_2D);

		// draw the images
		if (Vars::lists()->valid_active_list())
		{
			glColor3f(1.0f,1.0f,1.0f);
			for(size_t i=0; i<Vars::lists()->get_list().get_num_items() && i<static_cast<size_t>(6*num_grid_rows); i++)
			{
				int x_start, y_start;
				x_start = get_grid_size() * (i%6) + 1;
				y_start = get_grid_size() * (i/6);
				draw_item(Vars::lists()->get_list().get_image_id(i), x_start, y_start, get_grid_size());
			}
		}

		size_t help_lines_shown = 0;

		if (desc_str)
		{
			show_help(desc_str, 0, static_cast<int>(0.5 + win->len_y + 10 + SMALL_FONT_Y_LEN * help_lines_shown++));
			desc_str = 0;
		}

		// Display any name search text
		if (strlen(filter))
		{
			if (SDL_GetTicks() > (last_key_time+5000))
			{
				filter[0] = '\0';
				last_key_time = 0;
			}
			else
			{
				std::string tmp = std::string(item_list_find_str) + std::string("[") + std::string(filter) + std::string("]");
				show_help(tmp.c_str(), 0, static_cast<int>(0.5 + win->len_y + 10 + SMALL_FONT_Y_LEN * help_lines_shown++));
			}
		}

		// draw mouse over window help text
		if (show_help_text)
		{
			if (!resizing)
				for (size_t i=0; i<help_str.size(); ++i)
					show_help(help_str[i], 0, static_cast<int>(0.5 + win->len_y + 10 + SMALL_FONT_Y_LEN * help_lines_shown++));
			help_str.clear();
		}

		glDisable(GL_TEXTURE_2D);

		// draw the item grid
		glColor3f(newcol_r, newcol_g, newcol_b);
		rendergrid(6, num_grid_rows, 0, 0, get_grid_size(), get_grid_size());

		// if an object is selected, draw a green grid around it
		if (Vars::lists()->valid_active_list() && (quantities.selected == ITEM_EDIT_QUANT) && (selected_item_number < Vars::lists()->get_list().get_num_items()))
		{
			int x_start = selected_item_number%6 * get_grid_size();
			int y_start = static_cast<int>(selected_item_number/6) * get_grid_size();
			if ((SDL_GetTicks() - pickup_fail_time) < 250)
				glColor3f(0.8f,0.2f,0.2f);
			else
				glColor3f(0.0f, 1.0f, 0.3f);
			rendergrid(1, 1, x_start, y_start, get_grid_size(), get_grid_size());
			rendergrid(1, 1, x_start-1, y_start-1, get_grid_size()+2, get_grid_size()+2);
		}

		glEnable(GL_TEXTURE_2D);

		// draw the quantities over everything else so they always show
		if (Vars::lists()->valid_active_list())
		{
			glColor3f(1.0f,1.0f,1.0f);
			char str[80];
			for(size_t i=0; i<Vars::lists()->get_list().get_num_items() && i<static_cast<size_t>(6*num_grid_rows); i++)
			{
				int x_start, y_start, y_end;
				x_start = get_grid_size() * (i%6) + 1;
				y_start = get_grid_size() * (i/6);
				y_end = y_start + get_grid_size() - 1;
				safe_snprintf(str, sizeof(str), "%i", Vars::lists()->get_list().get_quantity(i));
				draw_string_small_shadowed(x_start, (i&1)?(y_end-15):(y_end-27), (unsigned char*)str, 1,1.0f,1.0f,1.0f, 0.0f, 0.0f, 0.0f);
			}
		}

		// Drawn the new list button (+) with highlight when mouse over
		if (mouse_over_add_button)
			glColor3f(0.99f,0.77f,0.55f);
		else
			glColor3f(newcol_r, newcol_g, newcol_b);
		draw_string_zoomed(add_button_x, add_button_y, (unsigned const char*)"+", 1, 2.0);

		// draw the item list names
		glColor3f(1.0f,1.0f,1.0f);
		int pos_y = get_grid_size()*num_grid_rows + get_list_gap();
		int num_shown = 0;
		const int top_entry = vscrollbar_get_pos (win_id, names_scroll_id);
		const std::vector<List> lists = Vars::lists()->get_lists();
		const int hl_width = static_cast<int>(win->len_x-ELW_BOX_SIZE-3);
		const int hl_height = static_cast<int>(names_list_height + get_list_gap());
		const size_t disp_chars = static_cast<size_t>((win->len_x-ELW_BOX_SIZE-2*get_list_gap()) / SMALL_FONT_X_LEN);
		for (size_t i = top_entry; i<lists.size() && num_shown<num_show_names_list; ++i)
		{
			if (i==Vars::lists()->get_active())
				draw_highlight(1, static_cast<int>(pos_y-get_list_gap()/2), hl_width, hl_height, 1);
			else if (i==name_under_mouse)
				draw_highlight(1, static_cast<int>(pos_y-get_list_gap()/2), hl_width, hl_height, 0);
			glColor3f(1.0f,1.0f,1.0f);
			if (lists[i].get_name().size() > disp_chars)
			{
				std::string todisp = lists[i].get_name().substr(0,disp_chars);
				draw_string_small(get_list_gap(), pos_y, reinterpret_cast<const unsigned char*>(todisp.c_str()), 1);
				if (i==name_under_mouse)
					show_help(lists[i].get_name().c_str(), 0, static_cast<int>(0.5 + win->len_y + 10 + SMALL_FONT_Y_LEN * help_lines_shown));
			}
			else
				draw_string_small(get_list_gap(), pos_y, reinterpret_cast<const unsigned char*>(lists[i].get_name().c_str()), 1);
			pos_y += static_cast<int>(names_list_height + get_list_gap());
			num_shown++;
		}

		if (clicked && (name_under_mouse < lists.size()))
		{
			do_click_sound();
			Vars::lists()->set_active(name_under_mouse);
		}

		if (clicked && mouse_over_add_button)
		{
			do_click_sound();
			new_or_rename_list(true);
		}
		name_under_mouse = static_cast<size_t>(-1);
		mouse_over_add_button = clicked = false;

#ifdef OPENGL_TRACE
CHECK_GL_ERRORS();
#endif //OPENGL_TRACE
		return 1;
	}