mirror of
https://github.com/storytold/LiveScan3D.git
synced 2026-10-09 00:09:58 +00:00
Playing sequences of .ply files now possible with the player.
This commit is contained in:
@@ -7,21 +7,21 @@ using System.IO;
|
||||
|
||||
namespace LiveScanPlayer
|
||||
{
|
||||
class FrameFileReader
|
||||
class FrameFileReaderBin : IFrameFileReader
|
||||
{
|
||||
BinaryReader binaryReader;
|
||||
int currentFrameIdx = 0;
|
||||
string filename;
|
||||
|
||||
public FrameFileReader(string filename)
|
||||
public FrameFileReaderBin(string filename)
|
||||
{
|
||||
this.filename = filename;
|
||||
binaryReader = new BinaryReader(File.Open(this.filename, FileMode.Open));
|
||||
}
|
||||
|
||||
~FrameFileReader()
|
||||
~FrameFileReaderBin()
|
||||
{
|
||||
Dispose();
|
||||
binaryReader.Dispose();
|
||||
}
|
||||
|
||||
public int frameIdx
|
||||
@@ -36,11 +36,6 @@ namespace LiveScanPlayer
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
binaryReader.Dispose();
|
||||
}
|
||||
|
||||
public void ReadFrame(List<float> vertices, List<byte> colors)
|
||||
{
|
||||
if (binaryReader.BaseStream.Position == binaryReader.BaseStream.Length)
|
||||
@@ -99,6 +94,12 @@ namespace LiveScanPlayer
|
||||
}
|
||||
}
|
||||
|
||||
public void Rewind()
|
||||
{
|
||||
currentFrameIdx = 0;
|
||||
binaryReader.BaseStream.Seek(0, SeekOrigin.Begin);
|
||||
}
|
||||
|
||||
public string ReadLine()
|
||||
{
|
||||
StringBuilder builder = new StringBuilder();
|
||||
@@ -112,11 +113,5 @@ namespace LiveScanPlayer
|
||||
|
||||
return builder.ToString();
|
||||
}
|
||||
|
||||
public void Rewind()
|
||||
{
|
||||
currentFrameIdx = 0;
|
||||
binaryReader.BaseStream.Seek(0, SeekOrigin.Begin);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.IO;
|
||||
|
||||
namespace LiveScanPlayer
|
||||
{
|
||||
class FrameFileReaderPly : IFrameFileReader
|
||||
{
|
||||
string[] filenames;
|
||||
int currentFrameIdx = 0;
|
||||
|
||||
public FrameFileReaderPly(string[] filenames)
|
||||
{
|
||||
this.filenames = filenames;
|
||||
}
|
||||
|
||||
public int frameIdx
|
||||
{
|
||||
get
|
||||
{
|
||||
return currentFrameIdx;
|
||||
}
|
||||
set
|
||||
{
|
||||
JumpToFrame(value);
|
||||
}
|
||||
}
|
||||
|
||||
public void ReadFrame(List<float> vertices, List<byte> colors)
|
||||
{
|
||||
BinaryReader reader = new BinaryReader(new FileStream(filenames[currentFrameIdx], FileMode.Open));
|
||||
|
||||
string line = ReadLine(reader);
|
||||
while (!line.Contains("element vertex"))
|
||||
line = ReadLine(reader);
|
||||
string[] lineElems = line.Split(' ');
|
||||
int nPoints = Int32.Parse(lineElems[2]);
|
||||
while (!line.Contains("end_header"))
|
||||
line = ReadLine(reader);
|
||||
|
||||
for (int i = 0; i < nPoints; i++)
|
||||
{
|
||||
for (int j = 0; j < 3; j++)
|
||||
{
|
||||
vertices.Add(reader.ReadSingle());
|
||||
}
|
||||
for (int j = 0; j < 3; j++)
|
||||
{
|
||||
colors.Add(reader.ReadByte());
|
||||
}
|
||||
}
|
||||
|
||||
reader.Dispose();
|
||||
|
||||
currentFrameIdx++;
|
||||
if (currentFrameIdx >= filenames.Length)
|
||||
currentFrameIdx = 0;
|
||||
}
|
||||
|
||||
public void JumpToFrame(int frameIdx)
|
||||
{
|
||||
currentFrameIdx = frameIdx;
|
||||
if (currentFrameIdx >= filenames.Length)
|
||||
currentFrameIdx = 0;
|
||||
}
|
||||
|
||||
public void Rewind()
|
||||
{
|
||||
currentFrameIdx = 0;
|
||||
}
|
||||
|
||||
public string ReadLine(BinaryReader binaryReader)
|
||||
{
|
||||
StringBuilder builder = new StringBuilder();
|
||||
byte buffer = binaryReader.ReadByte();
|
||||
|
||||
while (buffer != '\n')
|
||||
{
|
||||
builder.Append((char)buffer);
|
||||
buffer = binaryReader.ReadByte();
|
||||
}
|
||||
|
||||
return builder.ToString();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace LiveScanPlayer
|
||||
{
|
||||
interface IFrameFileReader
|
||||
{
|
||||
int frameIdx
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
void ReadFrame(List<float> vertices, List<byte> colors);
|
||||
|
||||
void JumpToFrame(int frameIdx);
|
||||
|
||||
void Rewind();
|
||||
}
|
||||
}
|
||||
@@ -48,13 +48,15 @@
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="FrameFileReaderPly.cs" />
|
||||
<Compile Include="IFrameFileReader.cs" />
|
||||
<Compile Include="PlayerWindowForm.cs">
|
||||
<SubType>Form</SubType>
|
||||
</Compile>
|
||||
<Compile Include="PlayerWindowForm.Designer.cs">
|
||||
<DependentUpon>PlayerWindowForm.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="FrameFileReader.cs" />
|
||||
<Compile Include="FrameFileReaderBin.cs" />
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<EmbeddedResource Include="PlayerWindowForm.resx">
|
||||
|
||||
+26
-13
@@ -37,15 +37,16 @@
|
||||
this.btRemove = new System.Windows.Forms.Button();
|
||||
this.lFrameFilesListView = new System.Windows.Forms.ListView();
|
||||
this.chSaveFrames = new System.Windows.Forms.CheckBox();
|
||||
this.btnSelectPly = new System.Windows.Forms.Button();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// btSelect
|
||||
//
|
||||
this.btSelect.Location = new System.Drawing.Point(12, 41);
|
||||
this.btSelect.Name = "btSelect";
|
||||
this.btSelect.Size = new System.Drawing.Size(75, 23);
|
||||
this.btSelect.Size = new System.Drawing.Size(89, 23);
|
||||
this.btSelect.TabIndex = 0;
|
||||
this.btSelect.Text = "Select files";
|
||||
this.btSelect.Text = "Select bin files";
|
||||
this.btSelect.UseVisualStyleBackColor = true;
|
||||
this.btSelect.Click += new System.EventHandler(this.btSelect_Click);
|
||||
//
|
||||
@@ -53,7 +54,7 @@
|
||||
//
|
||||
this.btStart.Location = new System.Drawing.Point(12, 12);
|
||||
this.btStart.Name = "btStart";
|
||||
this.btStart.Size = new System.Drawing.Size(75, 23);
|
||||
this.btStart.Size = new System.Drawing.Size(89, 23);
|
||||
this.btStart.TabIndex = 1;
|
||||
this.btStart.Text = "Start player";
|
||||
this.btStart.UseVisualStyleBackColor = true;
|
||||
@@ -61,9 +62,9 @@
|
||||
//
|
||||
// btShow
|
||||
//
|
||||
this.btShow.Location = new System.Drawing.Point(12, 128);
|
||||
this.btShow.Location = new System.Drawing.Point(12, 157);
|
||||
this.btShow.Name = "btShow";
|
||||
this.btShow.Size = new System.Drawing.Size(75, 23);
|
||||
this.btShow.Size = new System.Drawing.Size(89, 23);
|
||||
this.btShow.TabIndex = 2;
|
||||
this.btShow.Text = "Show live";
|
||||
this.btShow.UseVisualStyleBackColor = true;
|
||||
@@ -79,9 +80,9 @@
|
||||
//
|
||||
// btRewind
|
||||
//
|
||||
this.btRewind.Location = new System.Drawing.Point(12, 99);
|
||||
this.btRewind.Location = new System.Drawing.Point(12, 128);
|
||||
this.btRewind.Name = "btRewind";
|
||||
this.btRewind.Size = new System.Drawing.Size(75, 23);
|
||||
this.btRewind.Size = new System.Drawing.Size(89, 23);
|
||||
this.btRewind.TabIndex = 5;
|
||||
this.btRewind.Text = "Rewind";
|
||||
this.btRewind.UseVisualStyleBackColor = true;
|
||||
@@ -89,9 +90,9 @@
|
||||
//
|
||||
// btRemove
|
||||
//
|
||||
this.btRemove.Location = new System.Drawing.Point(12, 70);
|
||||
this.btRemove.Location = new System.Drawing.Point(12, 99);
|
||||
this.btRemove.Name = "btRemove";
|
||||
this.btRemove.Size = new System.Drawing.Size(75, 23);
|
||||
this.btRemove.Size = new System.Drawing.Size(89, 23);
|
||||
this.btRemove.TabIndex = 6;
|
||||
this.btRemove.Text = "Remove file";
|
||||
this.btRemove.UseVisualStyleBackColor = true;
|
||||
@@ -100,10 +101,10 @@
|
||||
// lFrameFilesListView
|
||||
//
|
||||
this.lFrameFilesListView.LabelEdit = true;
|
||||
this.lFrameFilesListView.Location = new System.Drawing.Point(93, 12);
|
||||
this.lFrameFilesListView.Location = new System.Drawing.Point(107, 12);
|
||||
this.lFrameFilesListView.MultiSelect = false;
|
||||
this.lFrameFilesListView.Name = "lFrameFilesListView";
|
||||
this.lFrameFilesListView.Size = new System.Drawing.Size(422, 97);
|
||||
this.lFrameFilesListView.Size = new System.Drawing.Size(408, 139);
|
||||
this.lFrameFilesListView.TabIndex = 7;
|
||||
this.lFrameFilesListView.UseCompatibleStateImageBehavior = false;
|
||||
this.lFrameFilesListView.View = System.Windows.Forms.View.Details;
|
||||
@@ -113,18 +114,29 @@
|
||||
// chSaveFrames
|
||||
//
|
||||
this.chSaveFrames.AutoSize = true;
|
||||
this.chSaveFrames.Location = new System.Drawing.Point(435, 128);
|
||||
this.chSaveFrames.Location = new System.Drawing.Point(432, 157);
|
||||
this.chSaveFrames.Name = "chSaveFrames";
|
||||
this.chSaveFrames.Size = new System.Drawing.Size(83, 17);
|
||||
this.chSaveFrames.TabIndex = 8;
|
||||
this.chSaveFrames.Text = "save frames";
|
||||
this.chSaveFrames.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// btnSelectPly
|
||||
//
|
||||
this.btnSelectPly.Location = new System.Drawing.Point(12, 70);
|
||||
this.btnSelectPly.Name = "btnSelectPly";
|
||||
this.btnSelectPly.Size = new System.Drawing.Size(89, 23);
|
||||
this.btnSelectPly.TabIndex = 9;
|
||||
this.btnSelectPly.Text = "Select ply files";
|
||||
this.btnSelectPly.UseVisualStyleBackColor = true;
|
||||
this.btnSelectPly.Click += new System.EventHandler(this.btnSelectPly_Click);
|
||||
//
|
||||
// PlayerWindowForm
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(527, 166);
|
||||
this.ClientSize = new System.Drawing.Size(527, 190);
|
||||
this.Controls.Add(this.btnSelectPly);
|
||||
this.Controls.Add(this.chSaveFrames);
|
||||
this.Controls.Add(this.lFrameFilesListView);
|
||||
this.Controls.Add(this.btRemove);
|
||||
@@ -151,6 +163,7 @@
|
||||
private System.Windows.Forms.Button btRemove;
|
||||
private System.Windows.Forms.ListView lFrameFilesListView;
|
||||
private System.Windows.Forms.CheckBox chSaveFrames;
|
||||
private System.Windows.Forms.Button btnSelectPly;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ namespace LiveScanPlayer
|
||||
{
|
||||
public partial class PlayerWindowForm : Form
|
||||
{
|
||||
BindingList<FrameFileReader> lFrameFiles = new BindingList<FrameFileReader>();
|
||||
BindingList<IFrameFileReader> lFrameFiles = new BindingList<IFrameFileReader>();
|
||||
bool bPlayerRunning = false;
|
||||
|
||||
List<float> lAllVertices = new List<float>();
|
||||
@@ -52,7 +52,7 @@ namespace LiveScanPlayer
|
||||
{
|
||||
for (int i = 0; i < dialog.FileNames.Length; i++)
|
||||
{
|
||||
lFrameFiles.Add(new FrameFileReader(dialog.FileNames[i]));
|
||||
lFrameFiles.Add(new FrameFileReaderBin(dialog.FileNames[i]));
|
||||
|
||||
var item = new ListViewItem(new [] { "0", dialog.FileNames[i]});
|
||||
lFrameFilesListView.Items.Add(item);
|
||||
@@ -60,6 +60,25 @@ namespace LiveScanPlayer
|
||||
}
|
||||
}
|
||||
|
||||
private void btnSelectPly_Click(object sender, EventArgs e)
|
||||
{
|
||||
OpenFileDialog dialog = new OpenFileDialog();
|
||||
dialog.Multiselect = true;
|
||||
dialog.ShowDialog();
|
||||
|
||||
if (dialog.FileNames.Length == 0)
|
||||
return;
|
||||
|
||||
lock (lFrameFiles)
|
||||
{
|
||||
lFrameFiles.Add(new FrameFileReaderPly(dialog.FileNames));
|
||||
|
||||
|
||||
var item = new ListViewItem(new[] { "0", Path.GetDirectoryName(dialog.FileNames[0]) });
|
||||
lFrameFilesListView.Items.Add(item);
|
||||
}
|
||||
}
|
||||
|
||||
private void btStart_Click(object sender, EventArgs e)
|
||||
{
|
||||
bPlayerRunning = !bPlayerRunning;
|
||||
@@ -87,7 +106,6 @@ namespace LiveScanPlayer
|
||||
{
|
||||
int idx = lFrameFilesListView.SelectedIndices[0];
|
||||
lFrameFilesListView.Items.RemoveAt(idx);
|
||||
lFrameFiles[idx].Dispose();
|
||||
lFrameFiles.RemoveAt(idx);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user