Detecting human body poses in 3D with Vision
At a glance
| Item | Summary |
|---|---|
| Purpose | Render skeletons of 3D body pose points in a scene overlaying the input image. |
| App architecture | A Swift sample with the source-visible chain HumanBodyPose3DApp → ContentView → HumanBodyPoseImageModel → HumanBodySkeletonRenderer → Vision APIs. |
| Main patterns | Publisher-backed observable state |
| Project style | 8 scanned source file(s) across Swift, organized around ranked entry, type, and file boundaries. |
| Execution model | Source-visible boundaries: async declaration or closure, Task, @MainActor, Task closure isolated to MainActor, DispatchQueue.main.async; none alone proves a background thread. |
| State/event model | Source-visible mechanisms: ObservableObject, @Published, SwiftUI state property wrapper. |
| Key frameworks/packages | SwiftUI, Vision, Foundation, SceneKit, PhotosUI; these are source dependencies, not architecture labels. |
Project structure
Source bundle/
├── HumanBodyPose3DApp/
│ ├── HumanBodyPose3DApp.swift
│ ├── Models/
│ │ ├── HumanBodyPoseImageModel.swift
│ │ └── HumanBodyPose3DDetector.swift
│ ├── Views/
│ │ ├── PhotoSelectionView.swift
│ │ ├── ContentView.swift
│ │ ├── HumanBodySkeletonRenderer.swift
│ │ ├── SkeletonSceneView.swift
│ │ └── HumanBodyPoseImage.swift
│ └── Info.plist
├── Configuration/
│ └── SampleCode.xcconfig
└── HumanBodyPose3DApp.xcodeproj/
├── .xcodesamplecode.plist
└── project.pbxproj
Structure observations
- Architecturally prominent files are ranked from entry points and role-named declarations; resource-only paths are omitted.
- Primary languages: Swift.
- The verified tree contains 4 project/configuration file(s) and 14 source declaration(s).
Overall architecture
flowchart LR
N1["HumanBodyPose3DApp"]
N2["ContentView"]
N3["HumanBodyPoseImageModel"]
N4["HumanBodySkeletonRenderer"]
N5["Vision APIs"]
N1 --> N2
N2 --> N3
N3 --> N4
N4 --> N5
Reference code
HumanBodyPose3DApp/HumanBodyPose3DApp.swift:11 — architecture anchor
@main
struct HumanBodyPose3DApp: App {
var body: some Scene {
WindowGroup {
ContentView()
}
}
}Interpretation
The arrows summarize the source-visible entry, role-named types or folders, and framework direction; when nodes come from structural folders, the sequence is a high-level interpretation rather than proof that every adjacent node calls the next. Ownership is claimed only where the next section cites a stored property or assignment. The diagram is intentionally limited to the dominant path into Vision.
Ownership and state
classDiagram
HumanBodyPoseImage o-- Image : image
HumanBodyPoseImage o-- PHAsset : selectedAsset
HumanBodyPoseImage o-- ImageState : imageState
HumanBodyPoseImage o-- PhotosPickerItem : imageSelection
Ownership evidence
HumanBodyPose3DApp/Models/HumanBodyPoseImageModel.swift:29 — stored dependency or nearest verified ownership anchor
struct HumanBodyPoseImage: Transferable {
let image: Image
// ...
}| Owner | Object or state | Relationship | Mutation authority |
|---|---|---|---|
HumanBodyPoseImage |
Image (image) |
stores or receives | Initialized by the owner; the binding is immutable |
HumanBodyPoseImage |
PHAsset (selectedAsset) |
stores or receives | App/module collaborators |
HumanBodyPoseImage |
ImageState (imageState) |
stores or receives | Owning type writes; wider scope can read |
HumanBodyPoseImage |
PhotosPickerItem (imageSelection) |
stores or receives | App/module collaborators |
Composition arrows indicate a source-visible construction expression or locally owned value state; aggregation means the owner stores or receives a dependency without proving exclusive lifetime ownership.
Concurrency, scheduling, and thread safety
Evidence limit: actor isolation, async/await, or Task creation does not by itself prove background-thread execution; Sendable conformance alone does not prove thread-safe mutation.
| Concern | Source mechanism | Verified placement or handoff | Evidence |
|---|---|---|---|
| Suspension boundary | async declaration or closure |
The source declares or crosses an asynchronous boundary; it does not by itself establish background execution. | HumanBodyPose3DApp/Models/HumanBodyPose3DDetector.swift:42 |
| Task creation | Task |
The source creates an unstructured task; surrounding context determines inherited actor isolation. | HumanBodyPose3DApp/Models/HumanBodyPose3DDetector.swift:43 |
| Main isolation | @MainActor |
The cited annotation marks its attached declaration or closure as main-actor isolated. | HumanBodyPose3DApp/Models/HumanBodyPose3DDetector.swift:53 |
| Main isolation | Task closure isolated to MainActor |
The cited operation explicitly enters a main-actor-isolated region. | HumanBodyPose3DApp/Models/HumanBodyPose3DDetector.swift:53 |
| Queue scheduling | DispatchQueue.main.async |
The source addresses the main dispatch queue. | HumanBodyPose3DApp/Models/HumanBodyPoseImageModel.swift:92 |
@MainActor/MainActor.run, DispatchQueue.main, and RunLoop.main are reported as distinct isolation, queue, and event-loop mechanisms. A plain Task is kept separate from Task.detached; neither is labeled as a background thread.
Reference code
HumanBodyPose3DApp/Models/HumanBodyPose3DDetector.swift:42 — representative execution boundary
public func runHumanBodyPose3DRequestOnImage(fileURL: URL?) async {
// ...
guard let assetURL = fileURL else {
return
}
// ...
}State propagation, frameworks, and dependencies
Evidence limit: an import proves a source-level compilation dependency at the cited line; it does not prove runtime use, architectural adoption, or whether a Swift package is a direct application dependency.
| Category | Mechanism or module | Verified role | Evidence |
|---|---|---|---|
| State propagation | ObservableObject |
ObservableObject supplies an observation contract. | HumanBodyPose3DApp/Models/HumanBodyPose3DDetector.swift:15 |
| State propagation | @Published |
A published property can emit owner-controlled changes. | HumanBodyPose3DApp/Models/HumanBodyPose3DDetector.swift:17 |
| State propagation | SwiftUI state property wrapper |
A SwiftUI property wrapper supplies or observes UI state. | HumanBodyPose3DApp/Views/HumanBodyPoseImage.swift:54 |
| Source import | SwiftUI |
The cited file imports this module; runtime use and architectural role are not inferred. | HumanBodyPose3DApp/HumanBodyPose3DApp.swift:8 |
| Source import | Vision |
The cited file imports this module; runtime use and architectural role are not inferred. | HumanBodyPose3DApp/HumanBodyPose3DApp.swift:9 |
| Source import | Foundation |
The cited file imports this module; runtime use and architectural role are not inferred. | HumanBodyPose3DApp/Models/HumanBodyPose3DDetector.swift:8 |
| Source import | SceneKit |
The cited file imports this module; runtime use and architectural role are not inferred. | HumanBodyPose3DApp/Models/HumanBodyPose3DDetector.swift:10 |
| Source import | PhotosUI |
The cited file imports this module; runtime use and architectural role are not inferred. | HumanBodyPose3DApp/Models/HumanBodyPoseImageModel.swift:9 |
receive(on:) describes downstream delivery scheduling, while subscribe(on:) describes upstream subscription/request/cancel scheduling. An import Combine alone establishes neither behavior nor a Store, reducer, Redux, or other application architecture.
Class and protocol design
HumanBodyPose3DApp/HumanBodyPose3DApp.swift:12 — representative type boundary
@main
struct HumanBodyPose3DApp: App {
// ...
ContentView()
// ...
}| Type | Responsibility | Depends on or conforms to |
|---|---|---|
HumanBodyPose3DApp |
Application entry and top-level composition | App |
HumanBodyPoseImageModel |
Feature data or observable state | ObservableObject |
PhotoSelectionView |
User-interface presentation and input forwarding | View |
PhotoSelectorView |
User-interface presentation and input forwarding | View |
ContentView |
User-interface presentation and input forwarding | View |
HumanBodySkeletonRenderer |
Owns drawing, GPU, or presentation processing | NSObject |
SkeletonScene |
Scene lifecycle or scene-level composition | View |
PersonPlaceholderImageView |
User-interface presentation and input forwarding | View |
SelectablePersonPhotoView |
User-interface presentation and input forwarding | View |
ImageState |
Represents mutable feature state | Concrete collaborators/imported frameworks |
No local protocol conformance is claimed as protocol-oriented design; external framework conformances are listed only as dependencies.
Access control
| Symbol | Access | Verified effect | Likely rationale |
|---|---|---|---|
calculateLocalAngleToParent (HumanBodyPose3DApp/Models/HumanBodyPose3DDetector.swift:21) |
public |
The symbol is visible to importing modules. | Inference: make the declaration available across a module or target boundary. |
runHumanBodyPose3DRequestOnImage (HumanBodyPose3DApp/Models/HumanBodyPose3DDetector.swift:42) |
public |
The symbol is visible to importing modules. | Inference: make the declaration available across a module or target boundary. |
imageState (HumanBodyPose3DApp/Models/HumanBodyPoseImageModel.swift:43) |
private(set) |
Read access follows the declaration; writes remain in the private scope. | Inference: allow observation while reserving invariant-changing writes for the owner. |
getAssetFileURL (HumanBodyPose3DApp/Models/HumanBodyPoseImageModel.swift:68) |
private |
Use is restricted to the lexical declaration and same-file extensions allowed by Swift. | Inference: hide an implementation step that is not part of the collaboration surface. |
Reference code
HumanBodyPose3DApp/Models/HumanBodyPose3DDetector.swift:21 — representative boundary
public func calculateLocalAngleToParent(joint: VNHumanBodyPose3DObservation.JointName) -> simd_float3 {
var angleVector: simd_float3 = simd_float3()
// ...
}Swift declarations without a modifier are internal; explicit private, fileprivate, private(set), public, or open entries above are interpreted by language semantics. Objective-C/C samples instead rely on header and implementation boundaries, which are not equivalent to Swift lexical privacy.
Logic ownership and placement
| Logic | Owning type or file | Placement rationale |
|---|---|---|
| Application entry and top-level composition | HumanBodyPose3DApp |
The source’s App suffix makes this role explicit. |
| Feature data or observable state | HumanBodyPoseImageModel |
The source’s Model suffix makes this role explicit. |
| Owns drawing, GPU, or presentation processing | HumanBodySkeletonRenderer |
The source’s Renderer suffix makes this role explicit. |
| Scene lifecycle or scene-level composition | SkeletonScene |
The source’s Scene suffix makes this role explicit. |
| User-interface presentation and input forwarding | ContentView, PersonPlaceholderImageView, PhotoSelectionView, PhotoSelectorView |
The source’s View suffix makes this role explicit. |
Design patterns
| Pattern | Source evidence | Purpose or tradeoff |
|---|---|---|
| Publisher-backed observable state | HumanBodyPose3DApp/Models/HumanBodyPose3DDetector.swift:17 |
Published properties notify observers while mutation remains with the state object. |
Naming conventions
- Types: App: HumanBodyPose3DApp; Model: HumanBodyPoseImageModel; Renderer: HumanBodySkeletonRenderer; Scene: SkeletonScene; View: ContentView, PersonPlaceholderImageView, PhotoSelectionView, PhotoSelectorView, SelectablePersonPhotoView.
- Protocols: no local protocol declaration in the scanned source.
- Methods:
loadOriginalFileURL,getAssetFileURL,loadAssetFromID,loadTransferable,requestAuthorization,relate3DSkeletonProportionToImagePlane,computeOffsetOfRoot,createInputImage2DNode. - Files:
HumanBodyPose3DApp/HumanBodyPose3DApp.swift,HumanBodyPose3DApp/Models/HumanBodyPoseImageModel.swift,HumanBodyPose3DApp/Views/PhotoSelectionView.swift,HumanBodyPose3DApp/Views/ContentView.swift,HumanBodyPose3DApp/Views/HumanBodySkeletonRenderer.swift,HumanBodyPose3DApp/Models/HumanBodyPose3DDetector.swift.
Architecture takeaways
HumanBodyPose3DAppis the main source-visible entry or composition anchor for this sample.- Framework work reaches SwiftUI, Vision, SceneKit, PhotosUI through a deliberately small high-level chain; the detailed API graph remains inside the cited implementation files.
- Stored-property evidence identifies lifecycle collaboration; it does not by itself prove exclusive object ownership.
- Access-control conclusions separate verified language visibility from the likely design rationale.
- The source does not justify labeling the design protocol-oriented.
Source map
| Source file | Relevant symbols |
|---|---|
HumanBodyPose3DApp/HumanBodyPose3DApp.swift |
Cited implementation, HumanBodyPose3DApp, SwiftUI, Vision |
HumanBodyPose3DApp/Models/HumanBodyPoseImageModel.swift |
Cited implementation, DispatchQueue.main.async, PhotosUI, HumanBodyPoseImageModel, ImageState, TransferError, HumanBodyPoseImage |
HumanBodyPose3DApp/Models/HumanBodyPose3DDetector.swift |
Cited implementation, async declaration or closure, Task, @MainActor, Task closure isolated to MainActor, ObservableObject, @Published, Foundation, SceneKit, HumanBodyPose3DDetector |
HumanBodyPose3DApp/Views/HumanBodyPoseImage.swift |
SwiftUI state property wrapper, HumanBodyImage, PersonPlaceholderImageView, SelectablePersonPhotoView |
HumanBodyPose3DApp/Views/PhotoSelectionView.swift |
PhotoSelectionView, PhotoSelectorView |
HumanBodyPose3DApp/Views/ContentView.swift |
ContentView |
HumanBodyPose3DApp/Views/HumanBodySkeletonRenderer.swift |
HumanBodySkeletonRenderer |
HumanBodyPose3DApp/Views/SkeletonSceneView.swift |
SkeletonScene |