コード例 #1
0
ファイル: fdd.cpp プロジェクト: djdron/UnrealSpeccyP
//=============================================================================
//	eUdi::eTrack::Update
//-----------------------------------------------------------------------------
void eUdi::eTrack::Update()
{
	byte* src = data;
	int len = data_len - 8;
	sectors_amount = 0;
	for(int i = 0; i < len; ++i)
	{
		if(src[i] == 0xa1 && src[i+1] == 0xfe && Marker(i)) //find index data marker
		{
			assert(sectors_amount < MAX_SEC);
			sectors[sectors_amount].id = src + i + 2;
			sectors[sectors_amount].data = NULL;
			i += 8;
			for(; i < len; ++i)
			{
				if(src[i] == 0xa1 && Marker(i) && !Marker(i + 1)) //find data marker
				{
					if(src[i+1] == 0xf8 || src[i+1] == 0xfb)
					{
						sectors[sectors_amount].data = src + i + 2;
					}
					break;
				}
			}
			++sectors_amount;
		}
	}
}
コード例 #2
0
ファイル: MacGraph.c プロジェクト: rolk/ug
static void MacPolymark (short n, SHORT_POINT *points)
{
  int i;

  for (i=0; i<n; i++)
    Marker(points[i]);
}
コード例 #3
0
ファイル: memory.cpp プロジェクト: Zombiebest/Dolphin
/*
  Validate a node. Check to see that the node is "clean" in the sense
  that nothing has over/underwritten it etc.
*/
int wxMemStruct::ValidateNode ()
{
    char * startPointer = (char *) this;
    if (!AssertIt ()) {
        if (IsDeleted ())
            ErrorMsg ("Object already deleted");
        else {
            // Can't use the error routines as we have no recognisable object.
#ifndef __WXGTK__
             wxLogMessage(wxT("Can't verify memory struct - all bets are off!"));
#endif
        }
        return 0;
    }

/*
    int i;
    for (i = 0; i < wxDebugContext::TotSize (requestSize ()); i++)
      cout << startPointer [i];
    cout << endl;
*/
    if (Marker () != MemStartCheck)
      ErrorMsg ();
    if (* (wxMarkerType *) wxDebugContext::MidMarkerPos (startPointer) != MemMidCheck)
      ErrorMsg ();
    if (* (wxMarkerType *) wxDebugContext::EndMarkerPos (startPointer,
                                              RequestSize ()) !=
        MemEndCheck)
      ErrorMsg ();

    // Back to before the extra buffer and check that
    // we can still read what we originally wrote.
    if (Marker () != MemStartCheck ||
        * (wxMarkerType *) wxDebugContext::MidMarkerPos (startPointer)
                         != MemMidCheck ||
        * (wxMarkerType *) wxDebugContext::EndMarkerPos (startPointer,
                                              RequestSize ()) != MemEndCheck)
    {
        ErrorMsg ();
        return 0;
    }

    return 1;
}
コード例 #4
0
ファイル: ScatterPlot.cpp プロジェクト: Milfhunter/gpstk
  Marker ScatterPlot::pickNextMarker(int idx)
  {
    int cid = idx % mcvec.size();
    int mid = idx / mcvec.size();

    //throw an exception for did>dlist.size()
    //if possible try (midx/clist.size())%dlist.size()

    return Marker(mvec[mid], .75, mcvec[cid]);
  }
コード例 #5
0
ファイル: audio_marker.cpp プロジェクト: Gpower2/Aegisub
void SecondsMarkerProvider::GetMarkers(TimeRange const& range, AudioMarkerVector &out) const {
	if (!enabled->GetBool()) return;

	if ((range.length() + 999) / 1000 > (int)markers.size())
		markers.resize((range.length() + 999) / 1000, Marker(pen.get()));

	size_t i = 0;
	for (int time = ((range.begin() + 999) / 1000) * 1000; time < range.end(); time += 1000) {
		markers[i].position = time;
		out.push_back(&markers[i++]);
	}
}
コード例 #6
0
ファイル: explore_frontier.cpp プロジェクト: gt-ros-pkg/hrl
void ExploreFrontier::getVisualizationMarkers(std::vector<Marker>& markers)
{
  Marker m;
  m.header.frame_id = "map";
  m.header.stamp = ros::Time::now();
  m.id = 0;
  m.ns = "frontiers";
  m.type = Marker::ARROW;
  m.pose.position.x = 0.0;
  m.pose.position.y = 0.0;
  m.pose.position.z = 0.0;
  m.scale.x = 1.0;
  m.scale.y = 1.0;
  m.scale.z = 1.0;
  m.color.r = 0;
  m.color.g = 0;
  m.color.b = 255;
  m.color.a = 255;
  m.lifetime = ros::Duration(0);

  m.action = Marker::ADD;
  uint id = 0;
  for (uint i=0; i<frontiers_.size(); i++) {
    Frontier frontier = frontiers_[i];
    m.id = id;
    m.pose = frontier.pose;
    markers.push_back(Marker(m));
    id++;
  }

  ROS_INFO("Number of frontiers being published: %d. Removed: %d. Last count: %d, id: %d", (unsigned int)frontiers_.size(), lastMarkerCount_ - id, lastMarkerCount_, id);

  m.action = Marker::DELETE;
  for (; id < lastMarkerCount_; id++) {
    m.id = id;
    markers.push_back(Marker(m));
  }

  lastMarkerCount_ = markers.size();
}
コード例 #7
0
ファイル: MarkerHandler.cpp プロジェクト: GYGit/ffead-cpp
void MarkerHandler::initMarkers() {
	//Start DsORM markers
	validMarkers.push_back(Marker("@Entity", Marker::TYPE_CLASS, collectStr(2, "dataSourceName", "isEmbedded,false,true,false"),
			collectBool(2, false, false)));
	validMarkers.push_back(Marker("@Table", Marker::TYPE_CLASS, collectStr(1, "name")));
	validMarkers.push_back(Marker("@Column", Marker::TYPE_PROP, collectStr(1, "dbf")));
	validMarkers.push_back(Marker("@IdGenerate", Marker::TYPE_PROP, collectStr(7, "dbEntityType,,table,sequence,identity",
			"dbEntityName", "type,,increment,hilo", "hiValueColumn", "lowValue,32767", "entityColumn", "columnName")));
	validMarkers.push_back(Marker("@Id", Marker::TYPE_PROP, collectStr(1, "dbf")));
	validMarkers.push_back(Marker("@HasOne", Marker::TYPE_PROP, collectStr(2, "dmappedBy", "dfk")));
	validMarkers.push_back(Marker("@HasMany", Marker::TYPE_PROP, collectStr(2, "dmappedBy", "dfk")));
}
コード例 #8
0
Marker HybridTracker::Registry(const PreMarker& mk) const {
   Mat image = cv::imread(mk.path, cv::IMREAD_GRAYSCALE);
   if(image.empty()) {
      AVR_ERROR(Cod::Undefined, "It did not read the image file to build the marker");
   }
   vector<cv::KeyPoint> keys; Mat descs;
   methods.Detect(image, keys);
   methods.Extract(image, keys, descs);

   vector<Point2f> points;
   cv::KeyPoint::convert(keys, points);

   return Marker(image.size(), points, descs, mk.model);
}
コード例 #9
0
ファイル: profiler.cpp プロジェクト: mingpj2/stk-code
//-----------------------------------------------------------------------------
/// Push a new marker that starts now
void Profiler::pushCpuMarker(const char* name, const video::SColor& color)
{
    // Don't do anything when frozen
    if(m_freeze_state == FROZEN || m_freeze_state == WAITING_FOR_UNFREEZE)
        return;

    ThreadInfo& ti = getThreadInfo();
    MarkerStack& markers_stack = ti.markers_stack[m_write_id];
    double  start = getTimeMilliseconds() - m_time_last_sync;
    size_t  layer = markers_stack.size();

    // Add to the stack of current markers
    markers_stack.push(Marker(start, -1.0, name, color, layer));
}
コード例 #10
0
ファイル: fdd.cpp プロジェクト: open-develop/unrealspeccyp
//=============================================================================
//	eUdi::eTrack::Update
//-----------------------------------------------------------------------------
void eUdi::eTrack::Update()
{
	byte* src = data;
	int len = data_len - 8;
	sectors_amount = 0;
	int i = 0;
	while(i < len)
	{
		for(; i < len; ++i)
		{
			if(src[i] == 0xa1 && src[i+1] == 0xfe && Marker(i)) //find index data marker
			{
				sectors[sectors_amount].id = src + i + 2;
				sectors[sectors_amount].data = NULL;
				i += 8;
				break;
			}
		}
		int end = Min(len, i + 43); // data marker margin 30-SD, 43-DD
		for(; i < end; ++i)
		{
			if(src[i] == 0xa1 && Marker(i) && !Marker(i + 1)) //find data marker
			{
				if((i < len && src[i+1] == 0xf8) || src[i+1] == 0xfb)
				{
					sectors[sectors_amount].data = src + i + 2;
				}
				break;
			}
		}
		if(sectors_amount++ >= MAX_SEC)
		{
			assert(0); //too many sectors
		}
	}
}
コード例 #11
0
void MarkerLocatorComputation::addNewMarkerToFoundMarkersList(ARToolKitPlus::ARMarkerInfo *marker_found,
		vector<int> *detectedMarkersID,
		vector<tf::Pose> *detectedMarkersPoses){
	map<int,double>::iterator iter = mapID2Dimension.find(marker_found->id); //look for the marker in the lookup table
	double dimension = markersBaseWidth;
	if(iter != mapID2Dimension.end())
		dimension = iter->second; //value

	Marker newMarkFound = Marker(marker_found->id, dimension);
	tf::Pose camera2markerPose;
	ComputeMarkerToCameraPose(newMarkFound, camera2markerPose);

//	tf::Pose cameraPoseTf;
//	tf::poseMsgToTF(cameraPose,cameraPoseTf);
	camera2markerPose.mult(cameraPose, camera2markerPose);//the otput of this call overwrite camera2markerPose with the aspected final marker pose
	detectedMarkersID->push_back(marker_found->id);
	detectedMarkersPoses->push_back(camera2markerPose);
}
コード例 #12
0
ファイル: simpcomm.cpp プロジェクト: barry-scott/BarrysEmacs
static int left_or_right_marker( int right )
{
    if( !eval_arg( 1 ) )
        return 0;

    if( ml_value.exp_type() != ISMARKER )
    {
        error( FormatString("%s expects its argument to be a marker") <<
            cur_exec->p_proc->b_proc_name );
        return 0;
    }

    int n = ml_value.asMarker()->get_mark();
    Marker *m = EMACS_NEW Marker( bf_cur, n, right );
    ml_value = m;

    return 0;
}
コード例 #13
0
ファイル: TimelineBar.cpp プロジェクト: etnlGD/renderdoc
uint32_t TimelineBar::processDraws(QVector<Marker> &markers, QVector<uint32_t> &draws,
                                   const rdcarray<DrawcallDescription> &curDraws)
{
  uint32_t maxEID = 0;

  for(const DrawcallDescription &d : curDraws)
  {
    if(!d.children.isEmpty())
    {
      markers.push_back(Marker());
      Marker &m = markers.back();

      m.name = d.name;
      m.eidStart = d.eventId;
      m.eidEnd = processDraws(m.children, m.draws, d.children);

      maxEID = qMax(maxEID, m.eidEnd);

      if(d.markerColor[3] > 0.0f)
      {
        m.color = QColor::fromRgb(
            qRgb(d.markerColor[0] * 255.0f, d.markerColor[1] * 255.0f, d.markerColor[2] * 255.0f));
      }
      else
      {
        m.color = QColor(Qt::gray);
      }
    }
    else
    {
      if(!(d.flags & DrawFlags::SetMarker))
      {
        m_Draws.push_back(d.eventId);
        draws.push_back(d.eventId);
      }
    }

    maxEID = qMax(maxEID, d.eventId);
  }

  return maxEID;
}
コード例 #14
0
ファイル: Main.cpp プロジェクト: ptolemyjenkins/sparky-clone
	void initialise() {
		PI = Pi();
		frameCap = 60;
		inputCap = 60;
		updateCap = 240;

		play = false;
		drawing = false;
		verts = 50;
		speed = 4;
		circleColour = vec4(0.4, 0.3, 0.8, 1);
		mark = Marker(vec4(0.0, 0.6, 0.8, 1));
		glPointSize(10.0f);

		float theta[NUMBER] = {1,2,3,4,0,0};
		float radii[NUMBER] = {300,150,100,50,20,10};
		float rates[NUMBER] = {1,2,3,4*PI,5,6};

		initCircles(vec2(500,500),radii, rates, theta);
	}
コード例 #15
0
// ---------------------------------------------------------------------------
//	readAiffData
// ---------------------------------------------------------------------------
//
void 
AiffFile::readAiffData( const std::string & filename )
{
	ContainerCk containerChunk;
	CommonCk commonChunk;
	SoundDataCk soundDataChunk;
	InstrumentCk instrumentChunk;
	MarkerCk markerChunk;

	try 
	{
		std::ifstream s( filename.c_str(), std::ifstream::binary );
	
		//	the Container chunk must be first, read it:
		readChunkHeader( s, containerChunk.header );
        if ( !s )
        {
			Throw( FileIOException, "File not found, or corrupted." );
        }
		if ( containerChunk.header.id != ContainerId )
        {
			Throw( FileIOException, "Found no Container chunk." );
        }
		readContainer( s, containerChunk, containerChunk.header.size );
		
		//	read other chunks, we are only interested in
		//	the Common chunk, the Sound Data chunk, the Markers: 
		CkHeader h;
		while ( readChunkHeader( s, h ) )
		{			
			switch (h.id)
			{
				case CommonId:
					readCommonData( s, commonChunk, h.size );
					if ( commonChunk.channels != 1 )
					{
						Throw( FileIOException, 
							   "Loris only processes single-channel AIFF samples files." );
					}					
					if ( commonChunk.bitsPerSample != 8 &&
						 commonChunk.bitsPerSample != 16 &&
						 commonChunk.bitsPerSample != 24 &&
						 commonChunk.bitsPerSample != 32 )
					{
						Throw( FileIOException, "Unrecognized sample size." );
					}										
					break;
				case SoundDataId:
					readSampleData( s, soundDataChunk, h.size );
					break;
				case InstrumentId:
					readInstrumentData( s, instrumentChunk, h.size );
					break;
				case MarkerId:
					readMarkerData( s, markerChunk, h.size );
					break;
				default:
					s.ignore( h.size );
			}
		}
	
		if ( ! commonChunk.header.id || ! soundDataChunk.header.id )
		{
			Throw( FileIOException, 
				   "Reached end of file before finding both a Common chunk and a Sound Data chunk." );
		}
	}
	catch ( Exception & ex ) 
	{
		ex.append( " Failed to read AIFF file." );
		throw;
	}
	
	
	//	all the chunks have been read, use them to initialize
	//	the AiffFile members:
	rate_ = commonChunk.srate;
	
	if ( instrumentChunk.header.id )
	{
		notenum_ = instrumentChunk.baseNote;
		notenum_ -= 0.01 * instrumentChunk.detune;
	}
	
	if ( markerChunk.header.id )
	{
		for ( int j = 0; j < markerChunk.numMarkers; ++j )
		{
			MarkerCk::Marker & m = markerChunk.markers[j];
			markers_.push_back( Marker( m.position / rate_, m.markerName ) );
		}		
	}
	
	convertBytesToSamples( soundDataChunk.sampleBytes, samples_, commonChunk.bitsPerSample );
	if ( samples_.size() != commonChunk.sampleFrames )
	{
		notifier << "Found " << samples_.size() << " frames of "
				 << commonChunk.bitsPerSample << "-bit sample data." << endl;
		notifier << "Header says there should be " << commonChunk.sampleFrames 
				 << "." << endl;
	}
}
コード例 #16
0
ファイル: Marker.hpp プロジェクト: Milfhunter/gpstk
 /**
  * @return A clear marker.
  */
 static Marker clear() { return Marker(DOT,0,Color::CLEAR); }
コード例 #17
0
ファイル: mbfkill.c プロジェクト: bbs-io/mbse
/*
 *  Check files for age, and not downloaded for x days. If they match
 *  one of these criteria (setable in areas setup), the file will be
 *  move to some retire area or deleted, depending on the setup.
 *  If they are moved, the upload date is reset to the current date,
 *  so you can set new removal criteria again.
 */
void Kill(void)
{
    FILE		*pAreas;
    int			i, iAreas, iAreasNew = 0, iTotal = 0, iKilled =  0, iMoved = 0, rc, Killit;
    char		*sAreas, *newdir = NULL, *sTemp, from[PATH_MAX], to[PATH_MAX];
    time_t		Now;
    struct fileareas	darea;
    struct _fdbarea	*fdb_area = NULL, *dst_area = NULL;
    
    sAreas = calloc(PATH_MAX, sizeof(char));
    sTemp  = calloc(PATH_MAX, sizeof(char));

    IsDoing("Kill files");
    if (!do_quiet) {
	mbse_colour(CYAN, BLACK);
	printf("Kill/move files...\n");
    }

    snprintf(sAreas, PATH_MAX, "%s/etc/fareas.data", getenv("MBSE_ROOT"));

    if ((pAreas = fopen (sAreas, "r")) == NULL) {
	WriteError("Can't open %s", sAreas);
	die(MBERR_INIT_ERROR);
    }

    fread(&areahdr, sizeof(areahdr), 1, pAreas);
    fseek(pAreas, 0, SEEK_END);
    iAreas = (ftell(pAreas) - areahdr.hdrsize) / areahdr.recsize;
    Now = time(NULL);

    for (i = 1; i <= iAreas; i++) {

	fseek(pAreas, ((i-1) * areahdr.recsize) + areahdr.hdrsize, SEEK_SET);
	fread(&area, areahdr.recsize, 1, pAreas);

	if ((area.Available) && (area.DLdays || area.FDdays)) {

	    if (enoughspace(CFG.freespace) == 0)
		die(MBERR_DISK_FULL);

	    if (!do_quiet) {
		printf("\r%4d => %-44s    \b\b\b\b", i, area.Name);
		fflush(stdout);
	    }

	    /*
	     * Check if download directory exists, if not, create the directory.
	     */
	    if (access(area.Path, R_OK) == -1) {
		Syslog('!', "Create dir: %s", area.Path);
		newdir = xstrcpy(area.Path);
		newdir = xstrcat(newdir, (char *)"/");
		mkdirs(newdir, 0755);
		free(newdir);
		newdir = NULL;
	    }

	    if ((fdb_area = mbsedb_OpenFDB(i, 30)) == NULL)
		die(MBERR_GENERAL);

	    /*
	     * Now start checking the files in the filedatabase
	     * against the contents of the directory.
	     */
	    while (fread(&fdb, fdbhdr.recsize, 1, fdb_area->fp) == 1) {
		iTotal++;
		Marker();

		Killit = FALSE;
		if (!fdb.UploadDate)
		    Syslog('!', "Warning: file %s in area %d has no upload date", fdb.Name, i);

		if (area.DLdays) {
		    /*
		     * Test last download date or never downloaded and the
		     * file is more then n days available for download.
		     */
		    if ((fdb.LastDL) && (((Now - fdb.LastDL) / 84400) > area.DLdays)) {
			Killit = TRUE;
		    }
		    if ((!fdb.LastDL) && fdb.UploadDate && (((Now - fdb.UploadDate) / 84400) > area.DLdays)) {
			Killit = TRUE;
		    }
		}

		if (area.FDdays) {
		    /*
		     * Check filedate
		     */
		    if (fdb.UploadDate && (((Now - fdb.UploadDate) / 84400) > area.FDdays)) {
			Killit = TRUE;
		    }
		}

		if (Killit) {
		    do_pack = TRUE;
		    if (area.MoveArea) {
			fseek(pAreas, ((area.MoveArea -1) * areahdr.recsize) + areahdr.hdrsize, SEEK_SET);
			fread(&darea, areahdr.recsize, 1, pAreas);
			snprintf(from, PATH_MAX, "%s/%s", area.Path, fdb.Name);
			snprintf(to,   PATH_MAX, "%s/%s", darea.Path, fdb.Name);
			if ((rc = file_mv(from, to)) == 0) {
			    Syslog('+', "Move %s, area %d => %d", fdb.Name, i, area.MoveArea);
			    if ((dst_area = mbsedb_OpenFDB(area.MoveArea, 30))) {
				fdb.UploadDate = time(NULL);
				fdb.LastDL = time(NULL);
				mbsedb_InsertFDB(dst_area, fdb, FALSE);
				mbsedb_CloseFDB(dst_area);
			    }

			    /*
			     * Now again if there is a dotted version (thumbnail) of this file.
			     */
			    snprintf(from, PATH_MAX, "%s/.%s", area.Path, fdb.Name);
			    snprintf(to,   PATH_MAX, "%s/.%s", darea.Path, fdb.Name);
			    if (file_exist(from, R_OK) == 0)
				file_mv(from, to);

			    /*
			     * Unlink the old symbolic link
			     */
			    snprintf(from, PATH_MAX, "%s/%s", area.Path, fdb.LName);
			    unlink(from);

			    /*
			     * Create the new symbolic link
			     */
			    snprintf(from, PATH_MAX, "%s/%s", darea.Path, fdb.Name);
			    snprintf(to,   PATH_MAX, "%s/%s", darea.Path, fdb.LName);
			    symlink(from, to);

			    fdb.Deleted = TRUE;
			    if (mbsedb_LockFDB(fdb_area, 30)) {
				fseek(fdb_area->fp, - fdbhdr.recsize, SEEK_CUR);
				fwrite(&fdb, fdbhdr.recsize, 1, fdb_area->fp);
				mbsedb_UnlockFDB(fdb_area);
			    }
			    iMoved++;
			} else {
			    WriteError("Move %s to area %d failed, %s", fdb.Name, area.MoveArea, strerror(rc));
			}
		    } else {
			Syslog('+', "Delete %s, area %d", fdb.LName, i);
			fdb.Deleted = TRUE;
			if (mbsedb_LockFDB(fdb_area, 30)) {
			    fseek(fdb_area->fp, - fdbhdr.recsize, SEEK_CUR);
			    fwrite(&fdb, fdbhdr.recsize, 1, fdb_area->fp);
			    mbsedb_UnlockFDB(fdb_area);
			}
			iKilled++;
			snprintf(from, PATH_MAX, "%s/%s", area.Path, fdb.LName);
			unlink(from);
			snprintf(from, PATH_MAX, "%s/%s", area.Path, fdb.Name);
			unlink(from);
			snprintf(from, PATH_MAX, "%s/.%s", area.Path, fdb.Name);
			unlink(from);
		    }
		}
	    }

	    /*
	     * Now we must pack this area database otherwise
	     * we run into trouble later on.
	     */
	    mbsedb_PackFDB(fdb_area);
	    mbsedb_CloseFDB(fdb_area);
	    iAreasNew++;

	} /* if area.Available */
    }

    fclose(pAreas);

    Syslog('+', "Kill  Areas [%6d] Files [%6d] Deleted [%6d] Moved [%6d]", iAreasNew, iTotal, iKilled, iMoved);

    if (!do_quiet) {
	printf("\r                                                          \r");
	fflush(stdout);
    }

    free(sTemp);
    free(sAreas);
}
コード例 #18
0
 bool DetectPolygons::processFrameContainer(BaseFrameContainer *frm, BaseFrameSource *frameSource)
 {
     Shapes* shapes = frm->getShapes();
     std::vector<Point>  approxCurve;
     unsigned int size = 0;
     ///for each contour, analyze if it is a paralelepiped likely to be the marker
     for (unsigned int i=0;i<shapes->getContours().size();i++)
     {
         
         unsigned int contourSize = shapes->getContours()[i].size();
         //check it is a possible element by first checking is has enough points
         if (contourSize>(unsigned int)(frm->getFrame()->getMat().cols /15))
         {
             //approximate to a polygon - 1. limit slozitosti (pocet bodu krat cislo vs konstanta), 2. uzavreny
             
             double complexity = double(contourSize)*complexityKoef;
             complexity = complexity > maxComplexity ? maxComplexity : (complexity < minComplexity ? minComplexity : complexity);
             cv::approxPolyDP(  cv::Mat (shapes->getContours()[i]),approxCurve , complexity , onlyClosed);
             
             size = approxCurve.size();
             unsigned int one, two;
             
             if (approxCurve.size() >= 3) {
                 // remove inline points
                 for (unsigned int i = 0; i < size; i++) {
                     one = (i + 1)%size;
                     two = (i + 2)%size;
                     // rozdil smernic
                     double x1 = approxCurve[i].x, y1 =  approxCurve[i].y,
                            x2 = approxCurve[one].x, y2 =  approxCurve[one].y,
                            x3 = approxCurve[two].x, y3 =  approxCurve[two].y;
                     
                     float k = std::abs(((y2-y1)/(x2-x1)) - ((y3-y1)/(x3-x1)));
                     
                     float d1 = std::sqrt((float) (approxCurve[i].x-approxCurve[one].x)*(approxCurve[i].x-approxCurve[one].x) +
                                        (approxCurve[i].y-approxCurve[one].y)*(approxCurve[i].y-approxCurve[one].y));
                     
                     float d2 = std::sqrt((float) (approxCurve[i].x-approxCurve[two].x)*(approxCurve[i].x-approxCurve[two].x) +
                                          (approxCurve[i].y-approxCurve[two].y)*(approxCurve[i].y-approxCurve[two].y));
                         
                     // if angle is too small or points are too close
                     if (k < 0.2 || d1 < 0.04*d2) {
                         approxCurve.erase(approxCurve.begin()+one);
                         size--;
                     }
                 }
             }
             
             
             if (size >= minimalPolygonLines && size <= maximalPolygonLines)
             {
                 
                 //and is convex
                 if (!onlyConvex || cv::isContourConvex(Mat  (approxCurve)))
                 {
                     
                     float minDist=1e10;
                     if (minDistance > 0) {
                         for (int i=0;i<size;i++)
                         {
                             float d= std::sqrt((float) (approxCurve[i].x-approxCurve[(i+1)%size].x)*(approxCurve[i].x-approxCurve[(i+1)%size].x) +
                                                (approxCurve[i].y-approxCurve[(i+1)%size].y)*(approxCurve[i].y-approxCurve[(i+1)%size].y));
                             if (d<minDist) minDist=d;
                         }
                     }
                     if (minDist>=minDistance)
                     {
                         shapes->getMarkers().push_back(Marker());
                         for (unsigned int i=0;i<size;i++)
                         {
                             shapes->getMarkers().back().push_back( Point2f(approxCurve[i].x,approxCurve[i].y));
                         }
                     }
                 }
             }
         }
     }
     
     /// remove these elements whise corners are too close to each other
     //first detect candidates
     size = shapes->getMarkers().size();
     
     if (minimalPolygonLines==4 && maximalPolygonLines == 4) {
         for (unsigned int i=0;i<shapes->getMarkers().size();i++)
         {
             
             //trace a line between the first and second point.
             //if the thrid point is at the right side, then the points are anti-clockwise
             double dx1 = shapes->getMarkers()[i][1].x - shapes->getMarkers()[i][0].x;
             double dy1 =  shapes->getMarkers()[i][1].y - shapes->getMarkers()[i][0].y;
             double dx2 = shapes->getMarkers()[i][2].x - shapes->getMarkers()[i][0].x;
             double dy2 = shapes->getMarkers()[i][2].y - shapes->getMarkers()[i][0].y;
             double o = (dx1*dy2)-(dy1*dx2);
             
             if (o  < 0.0)		 //if the third point is in the left side, then sort in anti-clockwise order
             {
                 swap(shapes->getMarkers()[i][1],shapes->getMarkers()[i][3]);
             }
         }
     }
     
     
     vector<pair<int,int>  > TooNearCandidates;
     for (unsigned int i=0;i < size;i++)
     {
         // 	cout<<"Marker i="<<i<<MarkerCanditates[i]<<endl;
         //calculate the average distance of each corner to the nearest corner of the other marker candidate
         for (unsigned int j=i+1;j<size;j++)
         {
             unsigned int vertexCount = shapes->getMarkers()[i].size();
             if (vertexCount == shapes->getMarkers()[j].size()) {
                 float dist=0;
                 for (unsigned int c=0;c<vertexCount;c++)
                     dist+= std::sqrt(  (shapes->getMarkers()[i][c].x-shapes->getMarkers()[j][c].x)*(shapes->getMarkers()[i][c].x-shapes->getMarkers()[j][c].x)+(shapes->getMarkers()[i][c].y-shapes->getMarkers()[j][c].y)*(shapes->getMarkers()[i][c].y-shapes->getMarkers()[j][c].y));
                 dist/=vertexCount;
                 //if distance is too small
                 if (dist< 14) {
                     TooNearCandidates.push_back(pair<int,int>(i,j));
                 }
             }
         }
     }
     //mark for removal the element of  the pair with smaller perimeter
     vector<bool> toRemove (shapes->getMarkers().size(),false);
     for (unsigned int i=0;i<TooNearCandidates.size();i++) {
         if ( perimeter(shapes->getMarkers()[TooNearCandidates[i].first ])>perimeter(shapes->getMarkers()[ TooNearCandidates[i].second] ))
             toRemove[TooNearCandidates[i].second]=true;
         else toRemove[TooNearCandidates[i].first]=true;
     }
     
     //remove the invalid ones
     removeElements(shapes->getMarkers(),toRemove);
     
     return true;
 }
コード例 #19
0
ファイル: scannews.c プロジェクト: bbs-io/mbse
int get_xover(char *grpname, int startnr, int endnr, List **art)
{
    char	    cmd[81], *ptr, *ptr2, *resp, *p;
    int		    retval, dupe, done = FALSE;
    int		    nr;
    unsigned int    crc;
    POverview	    pov;

    snprintf(cmd, 81, "XOVER %d-%d\r\n", startnr, endnr);
    if ((retval = nntp_cmd(cmd, 224))) {
	switch (retval) {
	    case 412:	WriteError("No newsgroup selected");
			return RETVAL_NOXOVER;
	    case 502:	WriteError("Permission denied");
			return RETVAL_NOXOVER;
	    case 420:	Syslog('m', "No articles in group %s", grpname);
			return RETVAL_OK;
	}
    }

    while (done == FALSE) {
	resp = nntp_receive();
	if ((strlen(resp) == 1) && (strcmp(resp, ".") == 0)) {
	    done = TRUE;
	} else {
	    Marker();
	    Nopper();
	    pov = xoverview;
	    ptr = resp;
	    ptr2 = ptr;

	    /*
	     * First item is the message number.
	     */
	    while (*ptr2 != '\0' && *ptr2 != '\t')
		ptr2++;
	    if (*ptr2 != '\0')
		*(ptr2) = '\0';
	    nr = atol(ptr);
	    ptr = ptr2;
	    ptr++;

	    /*
	     * Search the message-id
	     */
	    while (*ptr != '\0' && pov != NULL && strcmp(pov->header, "Message-ID:") != 0) {
		/*
		 * goto the next field, past the tab.
		 */
		pov = pov->next;

		while (*ptr != '\t' && *ptr != '\0')
		    ptr++;
		if (*ptr != '\0')
		    ptr++;
	    }
	    if (*ptr != '\0' && pov != NULL) {
		/*
		 * Found it, now find start of msgid
		 */
		while (*ptr != '\0' && *ptr != '<')
		    ptr++;
		if(ptr != '\0') {
		    ptr2 = ptr;
		    while(*ptr2 != '\0' && *ptr2 != '>')
			ptr2++;
		    if (*ptr2 != '\0') {
			*(ptr2+1) = '\0';
			p = xstrcpy(ptr);
			p = xstrcat(p, grpname);
			crc = str_crc32(p);
			dupe = CheckDupe(crc, D_NEWS, CFG.nntpdupes);
			fill_artlist(art, ptr, nr, dupe);
			free(p);
			if (CFG.slow_util && do_quiet)
			    msleep(1);
		    }
		}
	    }
	}
    }

    return RETVAL_OK;
}
コード例 #20
0
ファイル: ugView.c プロジェクト: rolk/ug
static int RasterizeFile (FILE *stream, AWindowRecord *myWindow, short wx, short wy)
{
  char *buffer;                                                 /* input buffer						*/
  long blockSize;                                               /* METABUFFERSIZE					*/
  long blockUsed;                                               /* actual buffer size used			*/
  long itemCounter;                                             /* number of commands in buffer		*/
  char *data;                                                           /* data pointer in buffer			*/
  short fx,fy;                                                  /* file screen size					*/
  Fixed sx,sy;                                                  /* scaling factors					*/
  int i,error,j,size;
  char opCode;
  short x,y,r,g,b,n,lw,ts,m,ms,w;
  short x1,y1,x2,y2;
  short xx[SIZE],yy[SIZE];
  PolyHandle myPoly;
  char s[CSIZE];
  unsigned char c;
  RGBColor newColor;
  PaletteHandle myPalette;
  long l;

  /* get file parameters */
  rewind(stream);
  error = fread(&blockSize,4,1,stream); if (error!=1) return(1);       /* block size */
  error = fread(&fx,2,1,stream);            if (error!=1) return(1);       /* x size */
  error = fread(&fy,2,1,stream);        if (error!=1) return(1);       /* y size */

  /* compute scaling factors */
  sx = FixRatio(wx-1,fx-1);
  sy = FixRatio(wy-1,fy-1);

  /* default values */
  lw = 1;
  ts = 12;
  m = 0;
  ms = 6;

  /* allocate input buffer */
  buffer = malloc(blockSize);
  if (buffer==NULL) return(1);

  SetPort((GrafPtr)(myWindow->theWindow));
  EraseRect(&(myWindow->usableRect));

  /* loop through the blocks */
  while (!feof(stream))
  {
    /* read block parameters */
    error = fread(&blockUsed,4,1,stream);    if (error!=1) {free(buffer); return(1);}
    error = fread(&itemCounter,4,1,stream);  if (error!=1) {free(buffer); return(1);}
    error = fread(buffer,blockUsed,1,stream);if (error!=1) {free(buffer); return(1);}

    /* init pointer to next item */
    data = buffer;

    /* for all items */
    for (i=0; i<itemCounter; i++)
    {
      /* get op code */
      opCode = *(data++);

      switch (opCode)
      {
      case opMove :
        x = *((short *)data);
        data += 2;
        y = *((short *)data);
        data += 2;
        TRFMX(x);
        TRFMY(y);
        MoveTo(x,y);
        break;

      case opDraw :
        x = *((short *)data);
        data += 2;
        y = *((short *)data);
        data += 2;
        TRFMX(x);
        TRFMY(y);
        LineTo(x,y);
        break;

      case opPolyline :
        n = *((short *)data);
        data += 2;
        if (n>=SIZE) {free(buffer); return(2);}
        size = n<<1;
        memcpy(xx,data,size);
        data += size;
        memcpy(yy,data,size);
        data += size;
        for (j=0; j<n; j++)
        {
          TRFMX(xx[j]);
          TRFMY(yy[j]);
        }
        MoveTo(xx[0],yy[0]);
        for (j=1; j<n; j++) LineTo(xx[j],yy[j]);
        break;

      case opPolygon :
        n = *((short *)data);
        data += 2;
        if (n>=SIZE) {free(buffer); return(2);}
        size = n<<1;
        memcpy(xx,data,size);
        data += size;
        memcpy(yy,data,size);
        data += size;
        for (j=0; j<n; j++)
        {
          TRFMX(xx[j]);
          TRFMY(yy[j]);
        }
        if (n<3) break;
        myPoly = OpenPoly();
        MoveTo(xx[0],yy[0]);
        for (j=1; j<n; j++) LineTo(xx[j],yy[j]);
        LineTo(xx[0],yy[0]);
        ClosePoly();
        PaintPoly(myPoly);
        FramePoly(myPoly);
        KillPoly(myPoly);
        break;

      case opPolymark :
        n = *((short *)data);
        data += 2;
        if (n>=SIZE) {free(buffer); return(2);}
        size = n<<1;
        memcpy(xx,data,size);
        data += size;
        memcpy(yy,data,size);
        data += size;
        for (j=0; j<n; j++)
        {
          TRFMX(xx[j]);
          TRFMY(yy[j]);
        }
        for (j=0; j<n; j++) Marker(m,ms,xx[j],yy[j]);
        break;

      case opText :
        n = *((short *)data);
        data += 2;
        if (n>=CSIZE-1) {free(buffer); return(2);}
        memcpy(s,data,n);
        s[n] = 0;
        data += n;
        DrawString((ConstStr255Param)c2pstr(s));
        break;

      case opCenteredText :
        x = *((short *)data);
        data += 2;
        y = *((short *)data);
        data += 2;
        TRFMX(x);
        TRFMY(y);
        n = *((short *)data);
        data += 2;
        if (n>=CSIZE-1) {free(buffer); return(2);}
        memcpy(s,data,n);
        s[n] = 0;
        data += n;
        c2pstr(s);
        w = StringWidth((ConstStr255Param)s);
        MoveTo(x-w/2,y+ts/2);
        DrawString((ConstStr255Param)s);
        break;

      case opSetLineWidth :
        n = *((short *)data);
        data += 2;
        lw = n;
        PenSize(n,n);
        break;

      case opSetTextSize :
        n = *((short *)data);
        data += 2;
        ts = n;
        TextSize(n);
        break;

      case opSetMarker :
        n = *((short *)data);
        data += 2;
        m = n;
        break;

      case opSetMarkerSize :
        n = *((short *)data);
        data += 2;
        ms = n;
        break;

      case opSetColor :
        c = *((unsigned char *)data);
        data++;
        PmForeColor((short)c);
        break;

      case opSetEntry :
        c = *((unsigned char *)data);
        data++;
        r = (short) (*((unsigned char *)data));
        data++;
        g = (short) (*((unsigned char *)data));
        data++;
        b = (short) (*((unsigned char *)data));
        data++;
        myPalette = GetPalette(myWindow->theWindow);
        myWindow->red[c]   = newColor.red   = r<<8;
        myWindow->green[c] = newColor.green = g<<8;
        myWindow->blue[c]  = newColor.blue  = b<<8;
        SetEntryColor(myPalette,(short) c,&newColor);
        ActivatePalette(myWindow->theWindow);
        break;

      case opSetPalette :
        x = (short) (*((unsigned char *)data));
        data++;
        y = (short) (*((unsigned char *)data));
        data++;
        myPalette = GetPalette(myWindow->theWindow);
        for (j=x; j<=y; j++)
        {
          r = (short) (*((unsigned char *)data));
          data++;
          g = (short) (*((unsigned char *)data));
          data++;
          b = (short) (*((unsigned char *)data));
          data++;
          myWindow->red[j]   = newColor.red   = r<<8;
          myWindow->green[j] = newColor.green = g<<8;
          myWindow->blue[j]  = newColor.blue  = b<<8;
          SetEntryColor(myPalette,(short) j,&newColor);
        }
        ActivatePalette(myWindow->theWindow);
        break;

      case opNewLine :
        lw = *((unsigned char *)data);
        data++;
        c = *((unsigned char *)data);
        data++;
        x1 = *((short *)data);
        data += 2;
        y1 = *((short *)data);
        data += 2;
        x2 = *((short *)data);
        data += 2;
        y2 = *((short *)data);
        data += 2;
        TRFMX(x1);
        TRFMY(y1);
        TRFMX(x2);
        TRFMY(y2);
        PenSize(lw,lw);
        PmForeColor((short)c);
        MoveTo(x1,y1);
        LineTo(x2,y2);
        break;

      case opNewPolyline :
        lw = *((unsigned char *)data);
        data++;
        c = *((unsigned char *)data);
        data++;
        n = *((short *)data);
        data += 2;
        if (n>=SIZE) {free(buffer); return(2);}
        size = n<<1;
        memcpy(xx,data,size);
        data += size;
        memcpy(yy,data,size);
        data += size;
        for (j=0; j<n; j++)
        {
          TRFMX(xx[j]);
          TRFMY(yy[j]);
        }
        PenSize(lw,lw);
        PmForeColor((short)c);
        MoveTo(xx[0],yy[0]);
        for (j=1; j<n; j++) LineTo(xx[j],yy[j]);
        break;

      case opNewPolygon :
        c = *((unsigned char *)data);
        data++;
        n = *((short *)data);
        data += 2;
        if (n>=SIZE) {free(buffer); return(2);}
        size = n<<1;
        memcpy(xx,data,size);
        data += size;
        memcpy(yy,data,size);
        data += size;
        for (j=0; j<n; j++)
        {
          TRFMX(xx[j]);
          TRFMY(yy[j]);
        }
        if (n<3) break;
        PmForeColor((short)c);
        myPoly = OpenPoly();
        MoveTo(xx[0],yy[0]);
        for (j=1; j<n; j++) LineTo(xx[j],yy[j]);
        LineTo(xx[0],yy[0]);
        ClosePoly();
        PaintPoly(myPoly);
        FramePoly(myPoly);
        KillPoly(myPoly);
        break;

      case opNewPolymark :
        m = *((unsigned char *)data);
        data++;
        ms = *((unsigned char *)data);
        data++;
        c = *((unsigned char *)data);
        data++;
        n = *((short *)data);
        data += 2;
        if (n>=SIZE) {free(buffer); return(2);}
        size = n<<1;
        memcpy(xx,data,size);
        data += size;
        memcpy(yy,data,size);
        data += size;
        for (j=0; j<n; j++)
        {
          TRFMX(xx[j]);
          TRFMY(yy[j]);
        }
        PmForeColor((short)c);
        for (j=0; j<n; j++) Marker(m,ms,xx[j],yy[j]);
        break;

      case opNewText :
        ts = *((unsigned char *)data);
        data++;
        c = *((unsigned char *)data);
        data++;
        x = *((short *)data);
        data += 2;
        y = *((short *)data);
        data += 2;
        TRFMX(x);
        TRFMY(y);
        n = *((short *)data);
        data += 2;
        if (n>=CSIZE-1) {free(buffer); return(2);}
        memcpy(s,data,n);
        s[n] = 0;
        data += n;
        MoveTo(x,y);
        TextSize(ts);
        PmForeColor((short)c);
        DrawString((ConstStr255Param)c2pstr(s));
        break;

      case opNewCenteredText :
        ts = *((unsigned char *)data);
        data++;
        c = *((unsigned char *)data);
        data++;
        x = *((short *)data);
        data += 2;
        y = *((short *)data);
        data += 2;
        TRFMX(x);
        TRFMY(y);
        n = *((short *)data);
        data += 2;
        if (n>=CSIZE-1) {free(buffer); return(2);}
        memcpy(s,data,n);
        s[n] = 0;
        data += n;
        c2pstr(s);
        w = StringWidth((ConstStr255Param)s);
        TextSize(ts);
        PmForeColor((short)c);
        MoveTo(x-w/2,y+ts/2);
        DrawString((ConstStr255Param)c2pstr(s));
        break;

      default :
        break;
      }
    }
  }

  return(0);
}
コード例 #21
0
ファイル: csvmidi.c プロジェクト: Chen-Leon/DeviationX
    { "Title_t", Meta(TrackTitleMetaEvent) },
    { "Instrument_name_t", Meta(TrackInstrumentNameMetaEvent) },
    { "Lyric_t", Meta(LyricMetaEvent) },
    { "Marker_t", Meta(MarkerMetaEvent) },
    { "Cue_point_t", Meta(CuePointMetaEvent) },
    { "Channel_prefix", Meta(ChannelPrefixMetaEvent) },
    { "MIDI_port", Meta(PortMetaEvent) } ,
    { "End_track", Meta(EndTrackMetaEvent) },
    { "Tempo", Meta(SetTempoMetaEvent) },
    { "SMPTE_offset", Meta(SMPTEOffsetMetaEvent) },
    { "Time_signature", Meta(TimeSignatureMetaEvent) },
    { "Key_signature", Meta(KeySignatureMetaEvent) },
    { "Sequencer_specific", Meta(SequencerSpecificMetaEvent) },
    { "Unknown_meta_event", Meta(0xFF) },

    { "Header", Marker(Header) },
    { "Start_track", Marker(Start_track) },
    { "End_of_file", Marker(End_of_file) },
};

static char *progname;		      /* Program name string */
static int verbose = FALSE; 	      /* Debug output */
static int zerotol = FALSE;    	      /* Any warning terminates processing */
static int errors = 0;	    	      /* Errors and warnings detected */
static char *s = NULL;	    	      /* Dynamically expandable CSV input buffer */

/*  OUTBYTE  --  Store byte in track buffer.  */

static byte of[10];
static byte *trackbuf = NULL, *trackbufp;
static int trackbufl;
コード例 #22
0
void BSInterpolation::CalculateControlPoints()
{
    const int lowerDiagNo = 2; //m1
    const int upperDiagNo = 2; //m2
    const int diagNo = 5;

    int n = parameters.length();
    float** diagMatrix = (float**)malloc(sizeof(float*) * (n+1));
    float** lowerMatrix = (float**)malloc(sizeof(float*) * (n+1));
    for(int i = 1; i < n+1;i++){
        diagMatrix[i] = (float*)malloc(sizeof(float) * (diagNo+1));
        lowerMatrix[i] = (float*)malloc(sizeof(float) * (lowerDiagNo+1));
    }
    unsigned long* index = (unsigned long*)malloc(sizeof(unsigned long) * (n+1));

    initializeDiagonals(diagMatrix, n);

    float evenOdd = 0;
    LU(diagMatrix, n, lowerDiagNo, upperDiagNo, lowerMatrix, index, &evenOdd);

    //get d table
    float* dx = (float*)malloc(sizeof(float) * (n+1));
    float* dy = (float*)malloc(sizeof(float) * (n+1));
    float* dz = (float*)malloc(sizeof(float) * (n+1));
    for (int i = 1; i<n+1; i++) {
        dx[i] = markers[i-1]->point.x();
        dy[i] = markers[i-1]->point.y();
        dz[i] = markers[i-1]->point.z();
    }

    solveEq(diagMatrix, n , lowerDiagNo, upperDiagNo, lowerMatrix, index, dx);
    solveEq(diagMatrix, n , lowerDiagNo, upperDiagNo, lowerMatrix, index, dy);
    solveEq(diagMatrix, n , lowerDiagNo, upperDiagNo, lowerMatrix, index, dz);
    for (int i = 1; i<n+1; i++) {
        ControlPoints.append(Marker(dx[i], dy[i], dz[i], Qt::gray));
        //markers.append(&ControlPoints[i-1]);
    }
    delete dx;
    delete dy;
    delete dz;
    for(int i = 1; i < n+1; i++){
        delete diagMatrix[i];
        delete lowerMatrix[i];
    }
    delete index;
    delete diagMatrix;
    delete lowerMatrix;

    //3DIAG SOLVER
    /*
        //assume degree 3
        int p = 3;
        //basis functions
        int n1 = parameters.length();
        QList<float> a; //low diag  a
        QList<float> b; //middle diag   b
        QList<float> c; //upper diag   c
        QList<float> c_original;

        a.append(0);
        b.append(getBSplineWeight(parameters[0], 0, p, knots, n1-1)); //Ni{ti}
        c_original.append(getBSplineWeight(parameters[0], 1, p, knots, n1-1)); //Ni+1{ti}
        for (int i = 1; i<n1-1; i++) {
            b.append(getBSplineWeight(parameters[i], i, p, knots, n1-1)); //Ni{ti}
            a.append(getBSplineWeight(parameters[i], i-1, p, knots, n1-1)); //Ni-1{ti}
            c_original.append(getBSplineWeight(parameters[i], i+1, p, knots, n1-1)); //Ni+1{ti}
        }
        b.append(getBSplineWeight(parameters[n1-1], n1-1, p, knots, n1-1)); //Ni{ti}
        a.append(getBSplineWeight(parameters[n1-1], n1-2, p, knots, n1-1)); //Ni-1{ti}
        c_original.append(0);

        //get d table
        QList<float> dx; //datapoints.x
        QList<float> dy;
        QList<float> dz;
        for (int i = 0; i<DataPoints.length(); i++) {
            dx.append(DataPoints[i]->point.x());
            dy.append(DataPoints[i]->point.y());
            dz.append(DataPoints[i]->point.z());
        }

        //SOLVE D=N*P to get P - control points
        //dx dy dz
        c = c_original;
        int n = n1-1;
        c[0] /= b[0];
        dx[0] /= b[0];
        dy[0] /= b[0];
        dz[0] /= b[0];
        for (int i = 1; i < n; i++) {
            c[i] /= b[i] - a[i]*c[i-1];
            dx[i] = (dx[i] - a[i]*dx[i-1]) / (b[i] - a[i]*c[i-1]);
            dy[i] = (dy[i] - a[i]*dy[i-1]) / (b[i] - a[i]*c[i-1]);
            dz[i] = (dz[i] - a[i]*dz[i-1]) / (b[i] - a[i]*c[i-1]);
        }
        dx[n] = (dx[n] - a[n]*dx[n-1]) / (b[n] - a[n]*c[n-1]);
        dy[n] = (dy[n] - a[n]*dy[n-1]) / (b[n] - a[n]*c[n-1]);
        dz[n] = (dz[n] - a[n]*dz[n-1]) / (b[n] - a[n]*c[n-1]);

        for (int i = n; i-- > 0;) {
            dx[i] -= c[i]*dx[i+1];
            dy[i] -= c[i]*dy[i+1];
            dz[i] -= c[i]*dz[i+1];
        }
        for (int i = 0; i<DataPoints.length(); i++) {
            ControlPoints.append(Marker(dx[i], dy[i], dz[i]));
            markers.append(&ControlPoints[i]);
        }
    */
}
コード例 #23
0
ファイル: mbfpack.c プロジェクト: bbs-io/mbse
/*
 *  Removes records who are marked for deletion. If there is still a file
 *  on disk, it will be removed too.
 */
void PackFileBase(void)
{
    FILE    *pAreas;
    int	    i, iAreas, iAreasNew = 0, rc, iTotal = 0, iRemoved = 0;
    char    *sAreas, fn[PATH_MAX];
    struct _fdbarea *fdb_area = NULL;
    int	    purge;

    sAreas = calloc(PATH_MAX, sizeof(char));

    IsDoing("Pack filebase");
    if (!do_quiet) {
	mbse_colour(CYAN, BLACK);
	printf("Packing file database...\n");
    }

    snprintf(sAreas, PATH_MAX, "%s/etc/fareas.data", getenv("MBSE_ROOT"));

    if ((pAreas = fopen (sAreas, "r")) == NULL) {
	WriteError("Can't open %s", sAreas);
	die(MBERR_INIT_ERROR);
    }

    fread(&areahdr, sizeof(areahdr), 1, pAreas);
    fseek(pAreas, 0, SEEK_END);
    iAreas = (ftell(pAreas) - areahdr.hdrsize) / areahdr.recsize;

    for (i = 1; i <= iAreas; i++) {

	fseek(pAreas, ((i-1) * areahdr.recsize) + areahdr.hdrsize, SEEK_SET);
	fread(&area, areahdr.recsize, 1, pAreas);

	if (area.Available) {

	    if (enoughspace(CFG.freespace) == 0)
		die(MBERR_DISK_FULL);

	    if (!do_quiet) {
		printf("\r%4d => %-44s", i, area.Name);
		fflush(stdout);
	    }
	    Marker();

	    if ((fdb_area = mbsedb_OpenFDB(i, 30)) == NULL)
		die(MBERR_GENERAL);
	    purge = 0;

	    while (fread(&fdb, fdbhdr.recsize, 1, fdb_area->fp) == 1) {
		iTotal++;

		if ((fdb.Deleted) || (fdb.Double) || (strcmp(fdb.Name, "") == 0)) {
		    iRemoved++;
		    purge++;
		    if (fdb.Double) {
			Syslog('+', "Removed double record file \"%s\" from area %d", fdb.LName, i);
		    } else {
			Syslog('+', "Removed file \"%s\" from area %d", fdb.LName, i);
			snprintf(fn, PATH_MAX, "%s/%s", area.Path, fdb.LName);
			rc = unlink(fn);
			if (rc && (errno != ENOENT))
			    WriteError("PackFileBase(): unlink %s failed, result %s", fn, strerror(rc));
			snprintf(fn, PATH_MAX, "%s/%s", area.Path, fdb.Name);
			rc = unlink(fn);
			if (rc && (errno != ENOENT))
			    WriteError("PackFileBase(): unlink %s failed, result %s", fn, strerror(rc));
			/*
			 * If a dotted version (thumbnail) exists, remove it silently
			 */
			snprintf(fn, PATH_MAX, "%s/.%s", area.Path, fdb.Name);
			unlink(fn);
		    }
		    do_index = TRUE;
		}
	    }

	    if (purge)
		mbsedb_PackFDB(fdb_area);
	    mbsedb_CloseFDB(fdb_area);
	    iAreasNew++;

	} /* if area.Available */
    }

    fclose(pAreas);
    Syslog('+', "Pack  Areas [%6d] Files [%6d] Removed [%6d]", iAreasNew, iTotal, iRemoved);

    if (!do_quiet) {
	printf("\r                                                              \r");
	fflush(stdout);
    }

    free(sAreas);
}
コード例 #24
0
ファイル: plotter.cpp プロジェクト: DapengChalmers/ZSLAM_TX2
void Plotter::Special(View&, InputSpecial inType, float x, float y, float p1, float p2, float /*p3*/, float /*p4*/, int button_state)
{
    if(inType == InputSpecialScroll) {
        const float d[2] = {p1,-p2};
        const float is[2] = {rview.x.Size(),rview.y.Size() };
        const float df[2] = {is[0]*d[0]/(float)v.w, is[1]*d[1]/(float)v.h};

        ScrollView(-df[0], -df[1]);
    } else if(inType == InputSpecialZoom) {
        float scalex = 1.0;
        float scaley = 1.0;

#ifdef _OSX_
        if (button_state & KeyModifierCmd) {
#else
        if (button_state & KeyModifierCtrl) {
#endif
            scalex = 1-p1;
        }else{
            scaley = 1-p1;
        }

        const float c[2] = {
            track || trigger_edge ? last_track_val[0] : hover[0],
            hover[1]
        };

        ScaleView(scalex, scaley, c[0], c[1]);
    }

    // Update hover status (after potential resizing)
    ScreenToPlot( (int)x, (int)y, hover[0], hover[1]);
}

void Plotter::AddSeries(const std::string& x_expr, const std::string& y_expr,
    DrawingMode drawing_mode, Colour colour,
    const std::string& title, DataLog *log)
{
    if( !std::isfinite(colour.r) ) {
        colour = colour_wheel.GetUniqueColour();
    }
    plotseries.push_back( PlotSeries() );
    plotseries.back().CreatePlot(x_expr, y_expr, colour, (title == "$y") ? y_expr : title);
    plotseries.back().log = log;
    plotseries.back().drawing_mode = (GLenum)drawing_mode;
}

void Plotter::ClearSeries()
{
    plotseries.clear();
}

Marker& Plotter::AddMarker(Marker::Direction d, float value, Marker::Equality leg, Colour c )
{
    return AddMarker(Marker(d,value,leg,c));
}

Marker& Plotter::AddMarker( const Marker& marker )
{
    plotmarkers.push_back( marker );
    return plotmarkers.back();
}