How to read .OFF file(3D) with C++ [closed] - c++

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 months ago.
The community reviewed whether to reopen this question 9 months ago and left it closed:
Original close reason(s) were not resolved
Improve this question
I am trying to read the data from some .OFF files(Object File Format)and store them in certain data struture. They contain the description of the composing polygons of a geometric object,(From wiki) and look like this:
OFF
2903 5804 120
3.71636 2.34339 0
4.12656 0.642027 0
...
3 1955 2193 2185
3 2193 1965 2192
My understanding about the .OFF file structure is: Some header data on the very beginning. Data like ' 3.71636 2.34339 0' should be the coordinates of vertices. Data like '3 1955 2193 2185' should be 'the number of vertices of one face and the indexes of the vertices'. Is it correct?
I found some methods to read data with C++. But I didn't find a way to read different types of data in one file. Is there a good way to read different data from one file?
Is there a way to read the data row by row?
How can I calculate the normals based on the data in such .OFF file?

First see OFF fileformat descrition
Yes starting 3 numbers are header
its the number of points, faces, edges (the last is not very useful) So you know how big tables you have to allocate ahead before reading.
beware the first OFF line is optional...
Yes you can read more than one types from file
just use fstream/cin or fscanf or whatever you got at your disposal I usually use direct binary file access instead of text file functions (as I have my own) for more info see
Convert the Linux open, read, write, close functions to work on Windows
however file access functions depend also on used OS and programing environment so yours might be called differently.
Yes there is a way to read text file row by row (line by line)
You have to parse the text line by line I read the whole file into memory and scan byte by byte for line separators 13,10
Then parse line word by word by scanning for space,tab 32,9 or separators like ,;+- if I know ahead I am reading number then I consider any ASCII code not present in numbers as separator too.
Then convert string to number (atof()) and append it to target table. Beware the national setting of decimal point separator in OS might affect the conversion as the file itself might use different one so you should handle that either by converting the string or by changng the separator for the conversion.
Here an example of using std::ifstream to read line by line and parse wavefront file (similar to OFF but slightly more complex) The other answer is mine using my own functions for parsing instead...
compute face normal using cross product on 2 of its edges
This is very common way so if you have triangle:
3 1955 2193 2185
then:
normal = cross( pnt[1955]-pnt[2193] , pnt[2193]-pnt[2185] );
If you compute the normal consistently from the same edges across all faces and your mesh has strict winding rule then all normals would point outside or inside of your mesh too...

Related

Extracting Irregular Dates Associated with Specific Words in Single Cell with Multiple Lines in Excel [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 years ago.
Improve this question
This is my first post on here, so please excuse any mistakes.
I have a column of cells. Each cell contains a variable number of lines withing the cell. Most lines contain a date. The format of the date varies slightly. Sometimes it is in the format MM/DD/YYYY, sometimes it will be MM/DD/YY, etc. My goal is to extract the date associated with a specific word in each line. Also, each cell is on a row with an identifying number. Therefore, I need the output to be along the same row.
Example:
I have tried every extract date formula I can find and I have run into three problems:
how to pull multiple dates from the cell,
how to compensate for the fact that some rows have dates that are formatted differently, and
how to pull dates only associated with certain words on the same line as the date.
It appears that my best option would be to use Regular Expressions. However, I have just started playing around with VBA and every function I have found that seems related to my issue I have been unable to adapt to my specific problem. I was using this post as a guide to build my function initially, but I cannot get it to work: Extracting Multiple Dates from a single cell
Originally, I tried breaking the lines up by doing text to column and this formula:
=IF(SEARCH("Red",D2),DATE(MID(D2,SEARCH("??/??/20??",D2)+6,4),MID(D2,SEARCH("??/??/20??",D2),2),MID(D2,SEARCH("??/??/20??",D2)+3,2)), "No Red Date")
However, text to column was not working because of irregular spacing issues. And Blue 1 and Blue 2 is just there to compensate for if there are multiple Blue dates in the cell, which there often are
NOT AN ANSWER : It doesn't really need code, you can use MID FIND SUBSTITUTE quickly playing, I used the following
=IF(FIND(C$1,$B2,1)-11<11,MID($B2,1,10),MID($B2,FIND(C$1,$B2,1)-11,10))
Which gives this,

How to parse, read, and store only one column of .CSV file into an array in C++

I have a .CSV file that's storing data from a laser. It records the height of the laser beam every second.
The .CSV file ends up having rows for each measurement that are all in this format:
DR,04,#
where the # is the height reading.
For example, if the beam is at a height of 10, the reading would say:
DR,04,10.
I want my program in C++ to read only the height (third column of the .CSV) from each row and put it into an array. I do not want the first two columns at all. That way I end up with an array with just a bunch of height values from each measurement.
How do I do that?
You can use strtok() to separate out the three columns. And then just get the last value.
You could also just take the string and scan for the first comma, and then scan from there for the second comma. What follows is the value you are after.
You could also use sscanf() to parse out the individual values.
This really isn't a difficult problem, and there are many ways to approach it. That is why people are complaining that you probably should've tried something and then ask a question here when you get stuck on a specific question.

Reading a .WAV file in c and extracting frequencies from it [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I made a structure in C and read all data in dat structure using fread function,Actually i confused about that,what is actual "audio data" means original sample data?
and how can we extract frequencies from dat audio data.
And I can successfully read that data but cant understand what i have to do further.
Pl explain.
You can easily read a wav file , just follow this document.
https://ccrma.stanford.edu/courses/422/projects/WaveFormat/
As for extracting frequencies from the file you would need to apply a Fourier Transform to your data , which would convert your data from Amplitude Time to Frequency time domain.
http://en.wikipedia.org/wiki/Fast_Fourier_transform
An audio file, typically, consists of a header and "samples". The samples can be 8, 16 or 32 bit and integer or floating point. Some audio files store the audio samples in a compressed form (mp3 for example), where others store the data as "raw samples".
To analyse the frequency, you need to perform a "fourier transform", which will give you an array of "how much at this frequency". The actual fourier transform is quite complex to describe (it's certainly more than a few dozen lines).
If the samples are in integer form, you'll have to convert from integer to floating point by dividing each sample by the max value (255, 32767 or 231-1).
Here's a package of C++ code to do FFT. There are several others out there.
http://fftwpp.sourceforge.net/
Here is another example of performing the FFT. This one displays the results in a Windows GUI.
http://www.relisoft.com/Freeware/index.htm

C++ Read only random lines in a file

I had requirement to read text file but its too large then I decide to only read some lines in this file. Can I use seek method for jump given line? Then I can only read that line because that text file is too large reading whole file is wasting lot of time. If its not possible, any one give better solution for that? (seek to given line and read it) (I know binary text files are reading byte by byte)
ex of my file
event1 0
subevent 1
subevent 2
event2 3
(In my file after one event its display number of lines I want to seek for previous event)
Yes, you can seek to a point in the file then read from there. One possible problem is that if the lines are all different lengths, a random location in the file will have a higher probability of being in a longer line: you're not getting evenly distributed probabilities of different lines. If you really really must have identical probabilities then you need to make at least one pass over the file to find the start of each line - then you can store those offsets in a vector and randomly select a vector element to guide seeking to the line data in the file. If you only care a little bit, then you can perhaps advance a small but random number of lines past the one you initially seek to... that will even the odds a bit, avoids the initial pass, but isn't perfect. hansmaad's comment adds a neat approach too - perfect results with pretty-good performance - but requires that you have all the lines numbered in the file itself.
Unless each line has exactly the same length, you're going to have to scan through it.
If you want to jump around in it, you can scan through it, saving the offset of each line in a container of your choice, and then use that to seek to a specific line.
Assuming that the lines are variable / random length, I don't believe there is any built-in way to jump directly to the start of a particular line. You can seek to an arbitrary byte position in the file. However, this might land anywhere in the beginning / middle / end of a line.
My best suggestion would be to attack the problem in two steps:
First, make a complete pass through the file, byte by byte, searching for the start of each line. Record the byte position of each line and store it into an array, vector, etc. (Basically, you are creating an index that maps from line number to starting position.) Then, when you have this index built up, you can easily jump to a particular line, by looking up the position in your index.
As far as I know, there is no built-in way to seek to a new line without already knowing where the lines are. I can't tell you the best way to achieve your goal, because most of your question details how you're trying to accomplish it, not what it is you're actually trying to accomplish. Therefore, I might go one of two ways with this:
1) If you actually need every last bit of data from the file (there is no metadata or other information that can be discarded):
Someone mentioned scanning through the file, tracking the lines as you go and building an index with it so you can read in one line at a time. This might work, and it would be the way to go if you actually need each line in its entirety, or if you only need the line number and plan on reading in small pieces at a time from there. However, without knowing details about your constraints or requirements, I would not recommend reading in entire lines using this method for one main reason: I have no way of knowing that one line will not itself be too large to load (what if there is only one line in the file?).
Instead, I would simply allocate a buffer of a size that is an appropriate amount to process at a time, and process the file in chunks of that size until you reach the end. You can stream more data in as you go. Without additional details, I can't tell you what that magic number should be, but the size of the largest chunk of information you might need to process is a good starting point as a minimum.
2) If you don't need every last bit of data from the file (you can discard some of the information in it), then you only need some of it. If you only need select pieces of data, then they are easier to find if they are tagged (which is what XML is for). There are lots of free XML parsers, or you can write your own. Then you'd search for tags instead of arbitrary line numbers, and changes to the file that result in the data being in a different location won't affect your ability to find it if it's tagged, as it would if you're just going by line numbers.

Where can I find some GPS unit test data? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 4 years ago.
Improve this question
Where can I find some GPS unit test data to validate my code?
For example:
Distance between two coordinates (miles / kilometers)
Heading/bearing from Point A to Point B
Speed from Ponit A to Point B given a duration
Right now I'm using Google Earth to fumble around with this, but it would be nice to know I'm validating my calculations against something, well, valid.
"GPS unit test data" is quite vague. You could easily have a pile of data, but if you don't know what they represent, what value are the tests?
If you're looking for a math sample of latitude/longitude calculations, check out the example on Wikipedia's Great Circle distances article: http://en.wikipedia.org/wiki/Great-circle_distance#Worked_example It has two points and works the math to compute the distance between them.
Or are you looking for the data that comes directly from a GPS unit? These are called NMEA sentences. An NMEA sentence begins with $GP and the next 3 characters are the sentence code, followed by the sentence data. http://aprs.gids.nl/nmea/ has a list.
You could certainly Google for "sample nmea data". The magnalox site appears to have some downloadable sample files, but I didn't check them to see if they'd be useful to you.
A better option would probably be to record your own data. Connect your laptop to your GPS unit, set it up to capture the serial data being emitted from the GPS, set the GPS to record your track, and take it for a short test drive. You can then compare how you processed the captured data based on what you know from the stored track (and from your little drive.) You could even have a web cam record the screen of the GPS to record heading/bearing information that doesn't arrive in the sentences.
Use caution if screen scraping NMEA sentences from a web site. All valid NMEA sentences begin with a "$GP"
RandomProfile offers randomly generated valid NMEA sentences.