Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(Open for checking code) New docs site for ARFlow's Unity Client #3

Merged
merged 25 commits into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
ffa3294
Add documentation for client-side code (and fix a little thing in ser…
legoeruro Aug 30, 2024
af99dd0
Define docfx configurations for unity docs generation
legoeruro Aug 30, 2024
cccfb47
Test github action to build client website
legoeruro Aug 30, 2024
7081f51
Update client.yml to remove warnings
legoeruro Aug 31, 2024
821ab54
Test to see if this runs github actions
legoeruro Aug 31, 2024
433222f
Test again
legoeruro Aug 31, 2024
ea6a3f1
Merge remote-tracking branch 'upstream/main'
legoeruro Sep 4, 2024
b155410
docs(contributor): contrib-readme-action has updated readme
github-actions[bot] Sep 4, 2024
acc5fb6
Change github actions for client website building and added some thin…
legoeruro Sep 4, 2024
a08aabe
Merge branch 'main' of https://github.com/legoeruro/ARFlow
legoeruro Sep 4, 2024
0ac19e4
re-test
legoeruro Sep 4, 2024
ec920cd
yet another fix
legoeruro Sep 4, 2024
d8beb1f
Move to correct directory
legoeruro Sep 4, 2024
0da4141
Remove unnecessary files
legoeruro Sep 4, 2024
58c2422
Modify for actions debugging
legoeruro Sep 4, 2024
d35240a
Debugging
legoeruro Sep 4, 2024
acd1daf
Test modify gitignore for website build
legoeruro Sep 4, 2024
2019ef4
Test including unity solution file
legoeruro Sep 4, 2024
34b9dc2
Add assembly-csproj to see if website docs is built
legoeruro Sep 4, 2024
3d0f9d5
Allow docs build with errors
legoeruro Sep 5, 2024
400aed7
Remove gitignored files
legoeruro Sep 5, 2024
b001d7d
Remove verbosed lines in build script
legoeruro Sep 5, 2024
45dddcd
Update gitignore and remove solution files
legoeruro Sep 5, 2024
707747c
Update gitignore
legoeruro Sep 5, 2024
bd37178
Again, updating this so that it runs with the gitignore
legoeruro Sep 5, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 41 additions & 2 deletions .github/workflows/website.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ on:
- 'python/**'
- '.github/workflows/website.yml'
- 'website/**'
- 'unity/**'

# Alternative: only build for tags.
# tags:
Expand All @@ -23,7 +24,30 @@ permissions:
contents: read

jobs:
build-docs:
build-client-docs-as-artifact:
legoeruro marked this conversation as resolved.
Show resolved Hide resolved
runs-on: windows-latest
steps:
- uses: actions/checkout@v4

- name: Install docfx
run: dotnet tool install -g docfx

- name: Run script to build the documentation
working-directory: ./unity/Documentation
run: ./scripts/build.cmd

# - name: Move docs to website directory
# run: |
# mkdir -p ./website/docs/client/
# cp -r ./unity/Documentation/clientHTMLOutput/* ./website/docs/client/
# Upload the website directory as an artifact
- uses: actions/upload-artifact@v4
with:
name: client-docs
path: ./unity/Documentation/clientHTMLOutput

build-server-docs:
needs: build-client-docs-as-artifact
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand Down Expand Up @@ -63,13 +87,28 @@ jobs:
mkdir -p ./website/docs/server/
cp -r ./python/docs/* ./website/docs/server/

# Get client docs to use as part of pages artifact
- uses: actions/download-artifact@v4
with:
name: client-docs
path: ./website/docs/client

# # cleanup client docs artifacts
# - name: Delete client docs artifact
# run: |
# github.rest.actions.deleteArtifact({
# owner: context.repo.owner,
# repo: context.repo.repo,
# artifact_id: ${{ steps.artifact-download.outputs.artifact-id }}
# });

- uses: actions/upload-pages-artifact@v3
with:
path: ./website

# Single deploy job since we're just deploying
deploy:
needs: build-docs
needs: build-server-docs
runs-on: ubuntu-latest
permissions:
pages: write
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ ExportedObj/
.consulo/
*.csproj
*.unityproj
# add .sln files to build documentation
*.sln
*.suo
*.tmp
Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ series = {HOTMOBILE '24}
<sub><b>Yiqin Zhao</b></sub>
</a>
</td>
<td align="center">
legoeruro marked this conversation as resolved.
Show resolved Hide resolved
<a href="https://github.com/legoeruro">
<img src="https://avatars.githubusercontent.com/u/68761938?v=4" width="100;" alt="legoeruro"/>
<br />
<sub><b>Khang Luu</b></sub>
</a>
</td>
<td align="center">
<a href="https://github.com/FelixNgFender">
<img src="https://avatars.githubusercontent.com/u/75899581?v=4" width="100;" alt="FelixNgFender"/>
Expand Down
1 change: 1 addition & 0 deletions unity/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ ExportedObj/
.consulo/
*.csproj
*.unityproj
# solution file is uploaded for doc building
*.sln
*.suo
*.tmp
Expand Down
16 changes: 16 additions & 0 deletions unity/Assets/Scripts/ARFlow/ARFlowClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,20 @@

namespace ARFlow
{
/// <summary>
/// This class represent the implementation for the client, using the gRPC protocol generated by Protobuf.
/// The client of ARFlow allows registering to the server and sending data frames to the server.
/// </summary>
public class ARFlowClient
{
private readonly GrpcChannel _channel;
private readonly ARFlowService.ARFlowServiceClient _client;
private string _sessionId;

/// <summary>
/// Initialize the client
/// </summary>
/// <param name="address">The address (AKA server URL) to connect to</param>
public ARFlowClient(string address)
{
var handler = new YetAnotherHttpHandler() { Http2Only = true };
Expand All @@ -27,6 +35,10 @@ public ARFlowClient(string address)
_channel.Dispose();
}

/// <summary>
/// Connect to the server with a request that contain register data of about the camera.
/// </summary>
/// <param name="requestData">Register data (AKA metadata) of the camera. The typing of this is generated by Protobuf.</param>
public void Connect(RegisterRequest requestData)
{
try
Expand All @@ -44,6 +56,10 @@ public void Connect(RegisterRequest requestData)
}
}

/// <summary>
/// Send a data of a frame to the server.
/// </summary>
/// <param name="frameData">Data of the frame. The typing of this is generated by Protobuf.</param>
public void SendFrame(DataFrameRequest frameData)
{
frameData.Uid = _sessionId;
Expand Down
40 changes: 39 additions & 1 deletion unity/Assets/Scripts/ARFlow/XRCpuImageExt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,33 @@

namespace ARFlow
{
/// <summary>
/// Interface for encoding CPU image
/// </summary>
internal interface IXRCpuImageEncodable
{
public byte[] Encode();
}

/// <summary>
/// Depth image information.
/// </summary>
internal struct XRDepthImage : IXRCpuImageEncodable
{
private XRCpuImage _image;

/// <summary>
/// Get Depth image from AROcclusionManager.
/// </summary>
public XRDepthImage(AROcclusionManager occlusionManager)
{
occlusionManager.TryAcquireEnvironmentDepthCpuImage(out _image);
}

/// <summary>
/// Encode depth image
/// </summary>
/// <returns>Depth image in bytes</returns>
public byte[] Encode()
{
return _image.GetPlane(0).data.ToArray();
Expand All @@ -30,6 +43,9 @@ public void Dispose()
}
}

/// <summary>
/// Depth image information with confidence
/// </summary>
internal struct XRConfidenceFilteredDepthImage : IXRCpuImageEncodable
{
private XRCpuImage _depthImage;
Expand All @@ -41,6 +57,11 @@ public Vector2Int Size()
return _depthImage.dimensions;
}

/// <summary>
/// Get depth and depth confidence from AROcclusionManager.
/// </summary>
/// <param name="occlusionManager"></param>
/// <param name="minConfidence">Min confidence for filtering</param>
public XRConfidenceFilteredDepthImage(AROcclusionManager occlusionManager, int minConfidence = 1)
{
// occlusionManager.TryAcquireEnvironmentDepthCpuImage(out _depthImage);
Expand All @@ -49,6 +70,12 @@ public XRConfidenceFilteredDepthImage(AROcclusionManager occlusionManager, int m
_minConfidence = minConfidence;
}

/// <summary>
/// For each depth value, if confidence is lower than minConfidence, it will be ignored (replaced with 0s).
/// The rest is encoded to bytes.
///
/// </summary>
/// <returns>Encoded bytes</returns>
public byte[] Encode()
{
var depthValues = _depthImage.GetPlane(0).data.ToArray();
Expand Down Expand Up @@ -83,6 +110,9 @@ public void Dispose()
}
}

/// <summary>
/// Color image information
/// </summary>
internal struct XRYCbCrColorImage : IXRCpuImageEncodable
{
private XRCpuImage _image;
Expand All @@ -91,7 +121,11 @@ internal struct XRYCbCrColorImage : IXRCpuImageEncodable
private readonly Vector2Int _nativeSize;
private readonly Vector2Int _sampleSize;


/// <summary>
/// Get image from ARCameraManager, and set scale to relative of sample (depth) size.
/// </summary>
/// <param name="cameraManager"></param>
/// <param name="sampleSize"></param>
public XRYCbCrColorImage(ARCameraManager cameraManager, Vector2Int sampleSize)
{
cameraManager.TryAcquireLatestCpuImage(out _image);
Expand All @@ -101,6 +135,10 @@ public XRYCbCrColorImage(ARCameraManager cameraManager, Vector2Int sampleSize)
_scale = _sampleSize.x / (float)_nativeSize.x;
}

/// <summary>
/// Resample color image to right size and convert to bytes.
/// </summary>
/// <returns>Encoded bytes</returns>
public byte[] Encode()
{
var size = _sampleSize.x * _sampleSize.y + 2 * (_sampleSize.x / 2 * _sampleSize.y / 2);
Expand Down
19 changes: 18 additions & 1 deletion unity/Assets/Scripts/ARFlowDeviceSample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@

public class ARFlowDeviceSample : MonoBehaviour
{
/// <summary>
/// Camera image data's manager from the device camera
/// </summary>
public ARCameraManager cameraManager;
/// <summary>
/// Depth data's manager from the device camera
/// </summary>
public AROcclusionManager occlusionManager;

public Button connectButton;
Expand Down Expand Up @@ -37,7 +43,10 @@ void Start()
// Application.targetFrameRate = 30;
}


/// <summary>
/// Get register request data from camera and send to server.
/// Image and depth info is acquired once to get information for the request, and is disposed afterwards.
/// </summary>
private void OnConnectButtonClick()
{
try
Expand Down Expand Up @@ -98,6 +107,10 @@ private void OnConnectButtonClick()
}
}

/// <summary>
/// On pause, pressing the button changes the _enabled flag to true (and text display) and data starts sending in Update()
/// On start, pressing the button changes the _enabled flag to false and data stops sending
/// </summary>
private void OnStartPauseButtonClick()
{
Debug.Log($"Current framerate: {Application.targetFrameRate}");
Expand All @@ -113,6 +126,10 @@ void Update()
UploadFrame();
}

/// <summary>
/// Get color image and depth information, and copy camera's transform from float to bytes.
/// This data is sent over the server.
/// </summary>
private void UploadFrame()
{
var colorImage = new XRYCbCrColorImage(cameraManager, _sampleSize);
Expand Down
Loading